Yii Framework Forum: Cgridview In 3Rd Party App - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cgridview In 3Rd Party App Rate Topic: -----

#1 User is offline   Termine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 18-October 11

Posted 01 May 2013 - 05:57 AM

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;
   Yii::import('zii.widgets.grid.*');

   $grid = new CGridView;
   $grid->dataProvider = $model->search();
   $grid->filter = $model;
   $grid->columns = array(
        array(
            'name'=>'name',
            'sortable'=>false,
        ),
        
        array(
            'name'=>'tag',
            'sortable'=>true,
        ),
        
        array(
            'header'=>'Date',
            'name'=>'date_time',
            'sortable'=>false,
        ),
    );

   $grid->init();
   $grid->run();

  //The model->search();
	public function search()
	{
		$criteria=new CDbCriteria;
		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('tag',$this->tag,true);
		$criteria->compare('date_time',$this->date_time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		    'pagination'=>array(
       			 'pageSize'=>10,
    		),

		));
	}



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.
0

#2 User is offline   Termine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 18-October 11

Posted 01 May 2013 - 01:45 PM

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.
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users