I have done a few applications with Yii now but this is the first time I am using urlFormat set to path. The reason I have is set this way is because my current application will be replacing something I did a few years ago that was programmed in CodeIgniter.
in my config file I define the urlManager like this
// uncomment the following to enable URLs in path-format
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'home'=>'site/index',
'programs/brief'=>'programs/index',
),
),
It’s basically the default setup for this component.
I am using CDataprovider and displaying the results in a view using CGridView.
This is my controller code, pretty basic
public function actionIndex()
{
$today= getdate();
$currentYear = $today['year'];
$dataProvider=new CActiveDataProvider('Event', array(
'pagination'=>array(
'pageSize'=>16,
),
'criteria'=>array(
'condition'=>'year(EventStartDate)>=:Year AND event_type_id=:TYPE',
'params'=>array(':Year'=>$currentYear,':TYPE'=>1),
'order'=>'EventStartdate ASC',
),
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
This is my view code, again, very basic.
<div class="main">
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
'EventName',
'EventStartdate',
'EventCost',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
</div>
The problem is the pager doesn’t work and sorting doesn’t work. I’m not sure why the sorting doesn’t work but the pager is creating incorrect URL’s.
With urlManager commented out (default setup) I get URL’s like this.
http://DomainName/index.php?r=programs/index&Event_page=2
With urlManager set ‘urlFormat’=>‘path’ I get URL’s like this
http://DomainName/programs/index?%2Fprograms%2Findex=&Event_page=2
The controller and action are output twice!
I also have the following code in .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Any help would be much appreciated.
Thanks,
doodle