smash
smash

Reputation: 13

Calling a function from the layout/view file in Yii

I am new to Yii framework and i need to define a function which is being called from /protected/views/layouts/main.php page. can i knw were to define it(Controller/model), so that i can get the corresponding action defined within the function.

Upvotes: 1

Views: 6277

Answers (1)

Ansari
Ansari

Reputation: 8218

Depending on what the function does and how visible you need it to be, you can do one of at least two things:

  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();.

Upvotes: 3

Related Questions