Pregunta

I need to create a class where we should have same methods shared with all my controllers, or almost all anyway.

So, I was looking for extending controller, but THEN, I notice that Controller Class already extends another class CController.

I'm confused.

Should we create our own class and extend CController, or extend Controller, or USE Controller class anyway ?

¿Fue útil?

Solución

You can write your common/shared methods in Controller , this class is created for that purpose only (that is your class, do whatever you want to do). no need to create another class.

Otros consejos

There is a little difference between them; Controller is just a child class of CController.

In test applications, it is used to provide additional variables into all controllers derived from Controller. For instance, it's used for setting of $breadcrumbs, $layout and menu $variables for a layout view file.

It's a good practice to extend YII base classes (starting with 'C' symbol) in your project - base classes won't be touched by YII framework updates and code would be more decoupled.

Controller is just a children class of CController. In this class code ralated $breadcrumbs, $layout and menu $variables for layout defined. If you use CController instead of controller you in SiteController.. you will get error.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top