How to get domain.com/userName/blog ?

Hello!

I’m Mark. I have just started my yii jurney, but I like it a lot :)

I want to build a multi user blog. I know there were some examples and tutorials on how to do this. But those do not implement one little detail. I’d like to let my users open their blogs like this:

Option 1:

domain.com/userName/xxx/

Option 2:

userName.domain.com/xxx/

xxx/ is a path to some resources (posts, settings and other things).

How can I achieve this? The second option would be much better but I think it would involve much more work. Am I right?

All the best,

Mark

Hi!

Actually option 2 isn’t too complicated.

In Apache’s conf just add the alias


<VirtualHost *:80> 

... 	

ServerAlias *.domain.com

...

</VirtualHost>

So, you’ve got all your subdomains redirected to the main and you can determine particular username value from $_SERVER[‘SERVER_NAME’]

Cheers,

Vit

Thanks! You’re right. This may be the easiest way.

I also found the way to deal with domain.com/user version.

It needs something like this added to urlManager rules:


'<user:\w+>'=>'blog',

'<user:\w+>/<controller:\w+>/'=>'<controller>/view',

O… and for those who may find it difficult to find this info, ‘user’ value (from the example above) is passed through to the action method. So if you have (for example) actionBlog, you should pass user value this way:


public function actionOther($user)

{

    // do something with $user variable

}

Works fine, except that pagination gets crazy when I use it, the link is not like I want it to be (but works!). Where does the pagination take path info from?

Regards,

Mark