How post/admin accept param ‘Post_page’ in blog demo’s “Manage Posts”?I searched the code in PostController/actionAdmin and views/post/admin but found nothing.I want to know how post/admin accept that param and make pagination.
public function actionAdmin()
{
$model=new Company('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Company']))
$model->attributes=$_GET['Company'];
// Here you can set that value
$model->Post_page = Yii::app()->request->getParam('Post_page');
$this->render('admin',array(
'model'=>$model,
));
}
In your model do like whatever you want to do
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('t.Post_page', $this->Post_page);
...
...
}
Yes,I do know how to get a param that passed to controller/action,but I cannot find property ‘Post_page’ in the file models/Post.php from the “blog” demo provided by yiiframwork.So,I think it’s magic.
The links regarding the pagination are rendered on the page by the pager (usually a CLinkPager object) of the grid, normally in the form of ‘Model_page=xx’ in $_GET parameter. And when you hit that link, the requested page will be interpreted on the server by the data provider (usually a CActiveDataProvider) that provides the data to the grid. For both the rendering and the interpreting, Yii uses CPagination object to make and get the pagination information. The jobs are performed rather deep inside the CGridView or the CActiveDataProvider and you will not see them directly in the controller or the view.
Please read the relevant topics in the API reference, and the source code of them if you would like. I think it’s worth doing.