how to use CHtml::link?

My problem is:

If my controller message is not in default controllers folder,but in a folder:center

so, the link is follow:


<?php echo CHtml::link('GoodBye', '/index?r=center/message/goodBye')?>

if I use ControllerId/ActionId format,

how to do?


<?php echo CHtml::link('GoodBye', 'center/message/goodBye')?>

is not work.

Hi, you must configure the urlManager application compontent in the main.php file (protected/config folder)


array(

    ......

    'components'=>array(

        ......

        'urlManager'=>array(

            'urlFormat'=>'path', <-- Add This

        ),

    ),

);



Details: http://www.yiiframework.com/doc/guide/1.1/en/topics.url

Did you enable urlManager in config/main.php?

OK, If I change the urlFormat path to my folder: center, but My another Controllers is not in the folder but in a news folder, how can I do?

example:

my controller HelloController is in center folder, and another controller NewsController,

HelloController code:




class HelloController extends Controller{

...


public function actionIndex(){

  $this->render('index');

}


}



NewsController:




class NewsController extends Controller{

...


public function actionIndex(){

  $this->render('index');

}


}



and the view Index.php for HelloController code is:




<?php echo CHtml("news", '/index.php?r=news/News/Index')?>



how can I use CHtml class to change the link: /index.php?r=news/News/Index as a fridly URL

Like ControllerId/ActionId? any idea?

First of, welcome to Yii!

Is your primary concern, which is how to use CHtml::link, already solved by rebus’ and austintodo’s replies? If so, maybe it would be best to all of us if you would state that your concern has been answered, and then create a different topic for your other concerns.

At any rate, I suggest you take a look at this.