[NOT] CUrl Manager Parsing BUG

Having these rules:

'http://forum.xyz.ro' => 'forum/default',            

'http://forum.xyz.ro/<url:[a-z0-9\-\._]+>-t-<id:\d+>-pg-<page:\d+>' => 'forum/showreplies/index',

'http://forum.xyz.ro/<url:[a-z0-9\-\._]+>-t-<id:\d+>' => 'forum/showreplies/index',

'http://forum.xyz.ro/<url:[a-z0-9\-\._]+>-<id:\d+>-pg-<page:\d+>' => 'forum/showtopics/index',

'http://forum.xyz.ro/<url:[a-z0-9\-\._]+>-<id:\d+>' => 'forum/showtopics/index',

When using a console application and trying to parse the routes like:




Results in :

in /home/xyz/public_html/protected/commands/SitemapCommand.php (65)

in /home/xyz/public_html/cron.php (15)

2011/05/10 02:23:11 [error] [php] Undefined index:  SERVER_NAME (/home/xyz/public_html/framework/web/CHttpRequest.php:240)

Stack trace:

#0 /home/xyz/public_html/protected/commands/SitemapCommand.php(65): CmsCUrlManager->createUrl()

#1 /home/xyz/public_html/framework/console/CConsoleCommandRunner.php(63): SitemapCommand->run()

#2 /home/xyz/public_html/framework/console/CConsoleApplication.php(88): CConsoleCommandRunner->run()

#3 /home/xyz/public_html/framework/base/CApplication.php(155): CConsoleApplication->processRequest()

#4 /home/xyz/public_html/cron.php(15): CConsoleApplication->run()

That’s not really a bug.

It’s a console application trying to access a server variable.

Which is not going to exist.

That is: SERVER_NAME is not set.

Because you are using createUrl.


Hold on: Are you trying to generate absolute URLs?

If you are, you cannot use http request servername, you need to store that in your configuration from the web app and retrieve it from your console app.

I had the same problem when trying to create absolute URLs for my emails as a shell command.

I am not sure if you can use createUrl at all, to be honest.

Relative or not.

In the console, there’s no such thing as an url. Practically speaking.

Correct me if I’m wrong.

I have a component that holds a lot of the website configuration.

One item is called baseUrl and it will return http://www.domain.com/ .

I am using that item, and append to it what the application should generate based on my rules(the relative url).

Even if it is a Console App, i can generate the urls for the other pages (you will notice that i am generating a sitemap in this case) but it seems like the only one that isn’t working is the forum, which is on a “sub-domain”.

Also, i have another console app, used for sending newsletter with all kind of links from the website. All those links are parsed okay with Yii::app()->urlManager->createUrl()

There should be an extra check there to see if SERVER_NAME is set or not in the $_SERVER $var and take the correct action in each of the cases.

Don’t really know, but this looks very much like a bug :)

In Yii or in PHP? :)

How can php-cli have any notion of server variables?

If you need a full-fledged web application from the command-line, then try REST.

Okay, this becomes very odd.

I could swear that the links were working in the newsletter mechanism, but for some reason, now they output something like:


Totally odd, and i am not in the mood to debug (maybe because i realized i got this wrong from the first time ? ).

How can php-cli have any notion of server variables?


Don’t know, maybe i was too tired when i wrote the code, but i still believe these were working at the moment i tested them .

Anyway, i changed the approach and i just build the urls manually, it’s not big deal.

Thanks for your posts here :)