Urlmanager: Path + Get At The Same Time

Hi everybody.

Have a little problem, finishing one of the projects. Configured UrlManager for SEF, but got troubles with AJAX.

Our scripter used “get” url format, when he was writing scripts. I don’t want to rewrite few thousand lines of code fixing urls.

Can I teach url manager work with get format (e.g. "/index.php?r=post/getStatistics") and path format (e.g. "/post/getStatistics") at the same time?

I’m thinking about add rewrite rule to .htaccess, but maybe there some easier ways to do it?

If you enable path format, get format will still work.

i also thought so, but all i’ve got is redirect to home page and ignorance of any get parameters.

Maybe you have a redirect somewhere in your .htaccess or your code? Yii doesn’t magically redirect to the homepage when a page doesn’t exist.

Try this in your index.php.




//create your app and store the app. Ignore the $env->configWeb it is just the way we configure our app.

$app = Yii::createWebApplication($env->configWeb); 

 

//Change the UrlFormat for urlManager to get if a get request is given instead of a path format one.

if (isset($_GET['r'])) {

    Yii::app()->urlManager->setUrlFormat('get');

}   


//run the app

$app->run(); 

Everything works perfectly now. Especially connecting with API’s where callback urls are usually in get format. I may also use my path formats for url rewritting. In a way it helps us use both get and path.

However…i feel it is not a long term solution and I will probably some day encounter a wicked bug lol.

Hope it helps someone. It worked for us =)