Controller Name in URL

Hi,

I’ve recently moved from CakePHP to Yii and I’m having some URL/routing problems.

I have a controller named, for example, myController and have a couple of requirements.

  1. I want a nice URL like ‘my-controller’, or ‘mycontroller’.

  2. I want to be able to do something like /my-controller/some-path/action

In order to do this I created the following routes:

‘/my-controller/’=>‘myController’,

‘/my-controller/<action>’=>‘myController/<action>’,

‘/my-controller/some-path/<action>’ => ‘myController/<action>’

They seem to work OK, but then I started using widget/actions (i.e. test.action) and the routes aren’t working for the ‘/my-controller/some-path/’. I just get a 404.

Also, with the urlManager -> urlFormat set to ‘path’ I can’t pass parameters to the controller with the / as opposed to name=value pairs. Again, I get a 404.

Any ideas?

Thanks,

Mark

Use Yii::createUrl to make your URLs and it should fix your problem.

Hi everybody,

i want to remove controller name from all of my site URLs. And i would like to redirect my site/index function with ‘/’.that is why i write a URL rules in config like this.




'urlManager'=>array(

			'urlFormat'=>'path',

		       'showScriptName'=>false,

			'rules'=>array(

			        '/'=>'site/index',

			        '<_a>'=>'<_c>/<_a>',

	     ),



But i realize that above write first URL is working and second URL rule is not working to remove controller name from URL for all controllers.

Anybody can help me out here.