YII架構這段代碼是啥意思?是moudles裡面view中default中的index.SegmentFault

來源:互聯網
上載者:User
breadcrumbs=array(    $this->module->id,);?>

uniqueId . '/' . $this->action->id; ?>

This is the view content for action "action->id; ?>".The action belongs to the controller ""in the "module->id; ?>" module.

You may customize this page by editing

我想知道這個$this是哪來的?這也沒有類啊!

回複內容:

breadcrumbs=array(    $this->module->id,);?>

uniqueId . '/' . $this->action->id; ?>

This is the view content for action "action->id; ?>".The action belongs to the controller ""in the "module->id; ?>" module.

You may customize this page by editing

我想知道這個$this是哪來的?這也沒有類啊!

注釋裡面不是寫了嗎?

$this DefaultController 

Yii view 裡面的$this 是指當前controller,具體過程去看conroller的render方法.
因為是用Yii自身的renderer,所以調用的是ViewRenderer類的renderFile方法,
這方法接收一個$context參數,其實傳的就是當前controller的執行個體對象,
然後再調這個controller的renderInternal方法,這個方法把view檔案require進來了,
所以在view的$this其實是把當前controller傳進來,然後調用傳進來的controller的自身方法,把view檔案require進來.

debug_print_backtrace 一看就知道

我心裡有答案,但沒實際用過YII,所以就只說方法了

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.