Calling A Function In A Different Controller

For I have a controller called Posts and the other called Search.

In the Posts controller i want to call the actionCreate() of the Search controller.

Search::create();

does not work! Any ideas?


include(Search.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

That is not the good design, You do not do any logic in your controller, instead delegate all of them to some other component class(It is commonly known as Service layer)




    Class PostController extends  Controller{

         private SerachComponent serachComponent;

         publuc function actionCreate(){

               Object o =  serachComponent.create();

               $this->render("", o)  ;

         }

    }


    Class SearchController extends  Controller{

        publuc function actionSearch(){

               Object o =  serachComponent.create();

               $this->render("", o)  ;

         }

    }



I highly suggest you to call PostController instead of Post. Post is kind a entity class and it should be Model.

do not make your controller fat with logic, instead delegate some other components, so you can use the component in any place. Never call controller method from another place, It is not intended for this purpose.

Try this:

Yii::app()->runController(‘search/create’);