Welcome Guest, Not a member yet? Register   Sign In
Problem with suddomains and controllers modeling.
#1

[eluser]smoku[/eluser]
Hello, I'm new to CodeIgniter, I understand everything from user-guide (I've been studing it for few days) but evet that I have a problem.

I'm trying to do a website in which user have their foto albums, comments, about me sites etc.

I'm trying to do links in this format:
www.domain.com/index.php/user/user_name - main page
www.doamin.com/index.php/user/user_name/album/album_id - album page

So I could easily redirect www.domain.com/index.php/user/user_name to user_name.domain.com, and users will have links: user_name.domain.com/album/album_id etc.

I have problems with modeling controllers for it, could someone help me? I think it's a common problem but I couldn't find the answer Sad

I did some think like this:

Code:
class User extends Controller {

    function User()
    {
        parent::Controller();    
    }
    
    function index($user = null)
    {
        if (!$user == null)
        {
            echo $user;
        }
        else
        {
            redirect('');
        }
    }
    
    function album($album_id = null)
    {
        if (!$album_id == null)
        {
            echo 'album: '.$album_id.'';
        }
        else
        {
            echo 'albums';
        }
    }
}


But link www.doamin.com/index.php/user/user_name/album/album_id isn't working.

I could create controllers for albums, comment etc. but the links would be domain.com/albums/album_id, so I won't be able to redirect it to user_name.domain.com.

Could anyone help me? Smile I'm programing in OOP a lot but I couldn't find how to do this.
#2

[eluser]Sarfaraz Momin[/eluser]
Well its pretty simple solution to this. Firstly you need to redirect all your subdomains to the main domain by creating wildcard DNS entry. Then you can use the internal routing of CI to identify what address is used in the address bar. If it is the domain just call the normal website. If it is a subdomain you can redirect it to a special controller method which can then pull the username from the URL and get the relevant user information based on that.

Hope it makes sense. Let me know if you have doubts and I would try to provide some code examples to support it.

Good Day !!!
#3

[eluser]smoku[/eluser]
Thanks Sarfaraz Momin for replay Smile

I know how to redirect (using wildcards) user_name.domain.com to domain.com/index.php/user/user_name

But the problem is how to do links like this: domain.com/index.php/user/index/user_name/album/album_id

If you have time read my example above. The problem is that controller can only make link: controller/method/parametr1/parametr1. Is there any posibillity to make links: controller/method1/parametr1/method2/parametr1/parametr2/ ? Because I need links: domain.com/index.php/user/user_name/album/album_id/. I think grono.net has such links. Or see slodkafotka.pl, both on MVC frameworks.

Thanks for your help! Smile

EDIT:
example:
http://grono.net/pub/u/1414339/gallery/4914823/
#4

[eluser]mvdg27[/eluser]
Hi,

I'm struggeling with this as well. I'd like to achieve the following:

When someone types username.mydomain.com I want to load the controller 'viewprofile' with 'username' as the parameter, so I can fetch the correct data from the database. The wildcard redirecting, isn't the problem. I have that covered. It's the correct routing, I guess.

Hope someone can post an example on this, as I think this might be usefull for others as well.

Cheers, Michiel




Theme © iAndrew 2016 - Forum software by © MyBB