Cgridview In 3Rd Party App

Hello there. After using Yii for new projects for a while now I am wanting to use Yii code in a 3rd party app. I am currently trying to use CGridView like so:

   //CGridView Widget

   $model = new SaveExport;


   $grid = new CGridView;

   $grid->dataProvider = $model->search();

   $grid->filter = $model;

   $grid->columns = array(



















  //The model->search();

	public function search()


		$criteria=new CDbCriteria;





		return new CActiveDataProvider($this, array(







However I keep getting CSort and CPagination errors because both classes try to call createUrl() using the controller object and there is no controller object. My question is how do I create a controller object for an app that only calls Yii::createWebApplication(’../includes/yii_config.php’); Is this even possible? If I remove pagination and sorting then it works but I know I am missing some fundamental knowledge about how to generate a dummy controller. I.E a controller that is only instantiated so CSort and CPagination can call the necessary controller methods.

OK. I answered by own question.

public function methodCalledByYour3rdPartyApp ()


   $route = 'export/admin'; //create a route

   Yii::app()->createController($route); // create a controller using that route

   Yii::app()->runController($route); // Run the controller for that route


You can then put all your Yii code under a ‘protected’ directory and use Yii just as you would if it was the main framework being used. E.g. working with models, controllers and views. I implemented the above using standard $this->widget() code rather than having to call a new CGridView like above.

You may have to tweak basePath and assetManager.basePath and baseUrl in config to suit your needs.