CUrlManager

I'm trying to understand why there is a URL manager component.

Friendly URLs seem to be the standard for frameworks so I'm not clear why, in such a framework, this component and subsequent routing rules are required to be hand-coded.

Right now, I have a rewrite rule in my web server conf that will rewrite all rules for any controller listed there,  but that means I have to maintain the web server config, too (not a big deal, just sayin').

In what situation would a developer prefer to have all the GET variables in the URI?  When would you use createURL to man-handle such data?

I saw a comment in the guide saying you could use the web server for all the rewrites but then you would lose the flexibility of createURL, so I'm trying to understand what flexibility it provides, which would imply there is a situation where you would want to display GET data in your URI.

I'm pretty green, but so far I like Yii, just not sure why the URL Manager is a component and not 'built-in' to create friendly URLs by default.

Thanks for any insight :)

Quote

I'm pretty green, but so far I like Yii, just not sure why the URL Manager is a component and not 'built-in' to create friendly URLs by default.

With yii most everything is a component (making it very modular).  You can not really say whether a component is "built in" or not, it is just there, and you may configure your application to use it or not in your config file.

This is what my configuration looks like, for example:

<?php


//..


	'components'=>array(


		'urlManager'=>array(


			'urlFormat'=>'path',


			'showScriptName' => false,


			//'caseSensitive'=>false,


			'rules'=>array(


				'user/register/*'=>'user/create',


				'user/settings/*'=>'user/update',


			),


		),


	),


//..


But you will configure the URL Manager in every app you have, won't you?  That is to say, is there a situation where you would not add it?

Alleviating these kinds of mundane tasks is one reason to use a framework.  Don't get me wrong, I really like the modularity when it comes to the functionality of the app itself, but creating friendly URLs by default seems like something the framework should 'just do' since it has such an impact on SEO.

The automagic stuff can go too far, as it does in other frameworks, but that doesn't really apply here.  Everyone wants friendly URLs but no one wants to maintain a bunch of rules for each controller that may require many.

The devs are obviously well-versed in the creation of web apps, so my question is: in what situation would you not want friendly URLs?

There must be a reason or some benefit I'm just not seeing.

I like Yii enough that I've already decided to move my current WIP over, and if updating my server config every time I make a change to the app is the only thing I have to worry about, then so be it.

Perhaps the yiic webapp tool should configure this by default then… Then you would not have to add it every time you start on a new app, assuming you want friendly urls on all your apps (like most people do). Perhaps you could ask Qiang to do this

Personally for me it's not a big deal, just a quick copy&past from an older app could do it.  Actually I start all my apps from a skeleton app I have created, which is personalized to me and has this kind of stuff.

Please propose a way to fully automatic creation of SEO URLs. I don't see any versatile. It will rely on some properties of objects - titles, tags, dates etc. CUrlManager is free from that.

It can create you everything in automated way if you just write:

'urlFormat'=>'path',

'showScriptName' => false,

And add .htaccess as described in manual.

But if you client wants to have

/clothing/some-product.html

instead of

/product/view/prodName/some-product.html

you should do it yourself in EVERY versatile framework. Yii just provides a nice way to do it :)

Konstantin,

CakePHP does exactly what I'm talking about (but goes too far in other areas).  I have a single rewrite command and that's it.  There is no configuring a component with a bunch of rules or maintaining a controller list in a server config file that's not part of the app.  The framework just does it, but if I want to configure the URLs in a different way, THEN I have to code something up, which IMO is the better way since most people want friendly URLs.