문제

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

도움이 되었습니까?

해결책

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'];

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top