Hello all, I am new to Yii ,i am learning to build a website with Yii,currently i am working on pagination part,
i have a little problem with pagination i am using an extension to load on the index.php page in that(extensions/dept) i have ShowDepts.php and a views folder under which i have a listing.php & _view.php file i have used CSqlDataprovider on ShowDepts.php and ClistView widget on listing.php where ‘itemView’=>’_view’
but i am getting Fatal error: Unsupported operand types in C:\xampp\htdocs\framework\web\CPagination.php on line 144
My files are ShowDepts.php
<?php
Yii::import("zii.widgets.CPortlet");
class ShowDepts extends CPortlet {
public $where = "";
// public $view = "index";
public $view = "listing";
public $link;
public function init() {
$this->link = new Link();
return parent::init();
}
private function getdepts() {
$query = "SELECT * FROM department ";
if ($this->where && is_string($this->where)) {
$query .= " where $this->where";
}
// echo $query;exit;
$command = Yii::app()->db->createCommand($query);
//return $cates = $command->queryAll();
$cates = $command->queryAll();
return $dp = new CSqlDataProvider($query, array(
'totalItemCount' => $cates,
'keyField' => 'link_rewrite',
'pagination' => array(
'pageSize' => 10,
),
));
}
public function renderContent() {
$dataProvider = $this->getdepts();
//print_r($categories);
$this->render($this->view, array('dataProvider' => $dataProvider));
return parent::renderContent();
}
}
?>
listing.php
<?php
$id = Yii::app()->user->getId();
?>
<?php
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'itemView' => '_view',
'template' => '{pager}{items}{pager}'
// 'viewData' => array('logged_in_id' => $id)
));
?>
_view.php
<div class="TabbedPanelsContent TabbedPanelsContentVisible" style="display: block;">
<ul>
<?php foreach ($categories as $category): ?>
<li>
<a title="<?php echo $category["departname"] ?>" href="<?php echo $this->link->deptDetailLink($category["link_rewrite"]) ?>" class="item_name">
<?php echo $category["departname"] ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>