English 中文(简体)
从 Yii 中的布局/视图文件中调用函数
原标题:Calling a function from the layout/view file in Yii
  • 时间:2012-05-26 13:18:26
  •  标签:
  • yii

我是Yii框架的新人,我需要定义一个从 / 受保护/ view/layouts/ main.php 页面调用的函数。 i knw 能够定义它( 主计长/ model), 这样我就可以在函数中找到相应的动作 。

最佳回答

取决于函数的作用以及你需要它有多明显,你至少可以做两件事之一:

  1. Extend the base CController class, define the function there, and then derive each of your controller classes from this new class. To invoke the function, you would run $this->myFunction();)
  2. Put the function in a model, instantiate an object of that model in the controller action function, and then invoke it in the view by $this->myModelObject->myFunction();.
问题回答

暂无回答




相关问题
how to change a model safe attributes in yii

I have a CActiveRecord model, and I need to change safe attributes list in that model. I have defined the safeAttributes method inside my model, like the following : public function safeAttributes() {...

Accessing a module s action rendered output

I m writing an "Account" module which should take care of everything about accounts: registration, login/logout, user administration, password recovery, account activation, etc. So I thought it would ...

yii components: events and behaviors?

i m currently learning the yii framework and have read their documentation. but i still don t understand the components. what are these. they talk about component events and behaviors. could someone ...

Yii: Customize the results of CAutoComplete

I need to make a dropdown list using CAutoComplete. Everything is set and works fine, here is my code of the action: <?php public function actionSuggestCharacter() { if(Yii::app()->...

热门标签