Question

I'm using Yii as a framework and I'm having trouble with this piece of code.

I want to output the apartments which has a "status" of "occupied"

So I have this CHtml link with querystring parameters

<?php echo CHtml::link('Occupied Apartments', array('/apartments/','status'=>'occupied')); ?>

But it still displays ALL outputs even if the status is "available". What must be the problem?

Any help would be appreciated

Was it helpful?

Solution

I think you are trying to construct the link as

   http://yourdomain.com/controller/action/status/xyzStatus

For this, First you have configure this URL structure in urlManager in your config file ie, main.php in protected/config/

Just add bellow line in urlManager rules

  '<controller:\w+>/<action:\w+>/<status:([A-Za-z0-9-]+)>' => '<controller>/<action>',

Finally your basic url rules will appear as

   'rules' => array(
            '<controller:\w+>/<action:\w+>/<status:([A-Za-z0-9-]+)>' => '<controller>/<action>', //This is newly added line
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
        ),

Now your url will work. You can get the status value with $_GET['status'];

OTHER TIPS

Please filter your data provider with $_GET['status']; mostly on conditions with CActiveDataProvider .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top