Hello guys, i’m not sure if this is a bug or just a mis understanding of the API by myself.
i try to make my table headings sortable. But i get the error: Controller does not have a method named "getDirections".
be aware of the normal sort on Daytrip and the relation sort of City.
thank you in advance.
Model:
public function relations()
{
return array(
'rCity' => array(self::BELONGS_TO, 'City', 'CityId', 'alias' => 'rCity'),
);
}
View:
<?php echo CSort::link('Daytrip'); ?>
<?php echo CSort::link('rCity.City'); ?>
Controller:
public function actionList()
{
$criteria = new CDbCriteria;
$withOption = array('rCity', 'rTag');
if(!empty($_GET['q']))
{
$criteria->condition = 'Daytrip LIKE "%' . $_GET['q'] . '%"';
$daytripCount = Daytrip::model()->with($withOption)->count($criteria);
}
else
{
$daytripCount = Daytrip::model()->with($withOption)->count($criteria);
}
$sort = new CSort('Daytrip');
$sort->defaultOrder = 'IdDaytrip ASC';
$sort->applyOrder($criteria);
$pages = new CPagination($daytripCount);
$pages->pageSize = Yii::app()->params['ItemsPerPage'];
$pages->applyLimit($criteria);
$daytrips = Daytrip::model()->with($withOption)->findAll($criteria);
$this->render('list', array('daytrips' => $daytrips, 'pages' => $pages));
}