Welcome Guest, Not a member yet? Register   Sign In
domain.com/$id or $username or w/e [solved]
#1

[eluser]DADE[/eluser]
Hello,

I have a problem:

Well. I need someting like this:

When someone enters http://example.com/, he sees welcome page or w/e. It's easy.

Code:
function index()
{
   $this->load->view('welcome');
}

But when someone enters http://example.com/Username, I need to load different page, witch shows info about user or w/e.

I tried something like:

Code:
function index()
{
    if($this->uri->segment(1) === FALSE)
    {
        $this->load->view('welcome');
    }
    else
    {
        $this->db->where('username', $this->uri->segment(1));
        $data['users'] = $this->db->get('users');
        $this->load->view('profile', $data);
    }
}

But of course it's not work.

So question is:

How I can load http://example.com and get welcome.php page, and how I can load http://example.com/username and get profile.php page?

I saw something about routes but I don't really understand something. :\ Maybe somebody write detailed information.

Thanks.
#2

[eluser]Clooner[/eluser]
See the very detailed user guide!

http://ellislab.com/codeigniter/user-gui...uting.html
#3

[eluser]DADE[/eluser]
Yes, and I need
Code:
$route[':any'] = "users/profile/$1";
But obviously if I'll do this, every example.com/something, will user this route. I don't need this. I still have some other pages like.

Boom: Idea runs through my brain. Big Grin Maybe if I'll write other routes all will be fine. Like:

Code:
$route[':any'] = "user/profile/$1";
$route['personal'] = "user/personal";
$route['embed'] = "user/embed";

I'll try and write back about result Big Grin
#4

[eluser]Clooner[/eluser]
[quote author="DADE" date="1283260423"]Yes, and I need
Code:
$route[':any'] = "users/profile/$1";
But obviously if I'll do this, every example.com/something, will user this route. I don't need this. I still have some other pages like.

Boom: Idea runs through my brain. Big Grin Maybe if I'll write other routes all will be fine. Like:

Code:
$route[':any'] = "user/profile/$1";
$route['personal'] = "user/personal";
$route['embed'] = "user/embed";

I'll try and write back about result Big Grin[/quote]
Again it's all in the manual!
[quote author="From the manual" date="1283260423"]
Note: Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.
[/quote]
It explains everything you want, just read and try it out!
#5

[eluser]DADE[/eluser]
Done, It works fine. Solved.




Theme © iAndrew 2016 - Forum software by © MyBB