Welcome Guest, Not a member yet? Register   Sign In
User profiles and routing
#1

[eluser]JamieBarton[/eluser]
Hi guys,

Here is my controller I've just set-up..

Now, I want to be able to go to some of the following URLs, and the appropriate views to show up. Hopefully someone can adjust my controller, and suggestion the Routes too..

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Users extends CI_Controller {
    
    public function index()
    {
        redirect(base_url());
    }
    
    public function view_profile()
    {
        $this->load->view('users/view_profile');
    }
    
    public function attending()
    {
        $this->load->view('users/attending');
    }
    
    public function venues()
    {
        $this->load->view('users/venues');
    }
    
    public function artists()
    {
        $this->load->view('users/artists');
    }
    
    public function friends()
    {
        $this->load->view('users/friends');
    }
    
    public function followers()
    {
        $this->load->view('users/followers');
    }
    
    public function following()
    {
        $this->load->view('users/following');
    }
}

/* End of file users.php */
/* Location: ./application/controllers/users.php */

The route I tried is:

Code:
$route['users/(:any)'] = "users/view_profile/$1";

However.. That would only pass in the username, but what I want to do, is go to the profile, append a method after the username, and get it to work properly..

Can't seem to get my head around how to do this.. Or it's late and I'm being silly..!


Thanks!

J Smile
#2

[eluser]JamieBarton[/eluser]
Okay

What I've done is:

Code:
$route['users/(:any)/attending'] = "users/attending/$1";
$route['users/(:any)/venues'] = "users/venues/$1";
$route['users/(:any)/artists'] = "users/artists/$1";
$route['users/(:any)/friends'] = "users/friends/$1";
$route['users/(:any)/followers'] = "users/followers/$1";
$route['users/(:any)/following'] = "users/following/$1";

$route['users/(:any)'] = "users/view_profile/$1";

But, if I put in a random anyting afer the username, it'll show the default method. I don't want that to happen..

I also think instead of all those routes, it could be shortened into 1?


Thanks

J Smile
#3

[eluser]JamieBarton[/eluser]
Anyone offer any help here?
#4

[eluser]SPeed_FANat1c[/eluser]
Quote:$route['users/(:any)/friends'] = "users/friends/$1";

As I understand the (:any) segment would be something like users id. And you want to execute function which finds the frieds by users id.

Why then not use such urls: domain.com/users/friends/id ? Then you will not need routing..
#5

[eluser]JamieBarton[/eluser]
I know that.. But I want to do it the other way Tongue




Theme © iAndrew 2016 - Forum software by © MyBB