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,所以就只說方法了