Welcome Guest, Not a member yet? Register   Sign In
(SOLVED) help with custom(nested) member pages site.com/username
#1

[eluser]Latavish[/eluser]
Hi Guys,

Was wondering if anyone could help me out with a small issue that I just can't seem to figure out. I'm putting together a CMS system that will allow members to have there own custom member page(s).

site.com/username

The good news is that i actually got it to work with the help of the forums by using this in my libraries folder.

(My_Router.php)
Code:
function _validate_request($segments)
    {
        // Does the requested controller NOT exist?
        if (!file_exists(APPPATH.'controllers/'.$segments[0].EXT))
        {
            $segments = array("profiles","main",$segments[0]);
            
        }
        
        return parent::_validate_request($segments);
    }

Here is where i'm stomped.

In my profiles controller I have added a function videos so this will show only the videos from this user. But for some reason because of the "My_Router" setup I can't seem to get this to work.

site.com/username/videos

It just shows the (site.com/username) page and the video function doesn't seem to work. Anyone have any ideas how I could get other functions withing the profiles controller to run?

I have noticed another thread where someone recommending Extending the router to accept DB query's as so,

Code:
/route["sql[SELECT id FROM users WHERE username = $1]"] = "user/profile/$1";

but not sure how or if this would work. Any help would be greatly appreciated.

Thanks a million guys.

Latavish
#2

[eluser]TheFuzzy0ne[/eluser]
Please post your controller.
#3

[eluser]Latavish[/eluser]
surly..here is my current controller

Code:
function main()
    {

        //Get User ID
        $user_id = $this->profile_functions->usernamechk($this->uri->segment(1));

        //Verify User in System
        if ($user_id == false) {
            echo '<h1>User Not Found!</h1>';

        } else {

            //Get User Profile Info
            $this->db->select('id, username, profile_views, join_date, country, gender, about_me, homepage');
            $this->db->where('id', $user_id);
            $q1 = $this->db->get('users', 1);
            $data['userquery'] = $q1->row();

            if ($q1->num_rows() != 1) {
                show_error('There was an Error Loading This Profile! If problem continues please contact the administator.');
            }


            $this->db->start_cache();
            $this->db->where('user_id', $user_id);
            $this->db->orderby('timestamp', 'desc');
            $this->db->stop_cache();

            //Get User Friends
            //$data['user_friends'] = $this->db->get('friends',12);
            $data['user_friends'] = $this->db->query("SELECT
users.icon,
users.username
FROM
users
Inner Join friends ON friends.friend_id = users.id
WHERE
friends.user_id =  $user_id");

            //Get User Videos
            $this->db->select('accesscode, title, user_id, thumbnail, duration, timestamp');
            $this->db->where('private', 0); //Do Not Display Private Items
            $this->db->where('encoded', 1);
            $data['user_videos'] = $this->db->get('videos', 8);

            //Get User Pictures
            $this->db->select('id, user_id, thumbnail, title, private, timestamp');
            $this->db->where('private', 0); //Only show public pics on profile
            $data['user_pictures'] = $this->db->get('images', 8);

            //Get Fav Videos
            //$data['user_fav_videos'] = $this->db->get('video_favorites',12);

            //Get Fav Pictures
            //$data['user_fav_pictures'] = $this->db->get('picture_favorites',9);

            $this->db->flush_cache();

            //Collect Comment Data
            $data['query'] = $this->db->query("SELECT
users.icon,
users.id,
profile_comments.`comment`,
profile_comments.`timestamp`,
profile_comments.`username`,
profile_comments.profile_userid,
profile_comments.user_id,
profile_comments.id
FROM
users
Inner Join profile_comments ON profile_comments.user_id = users.id
WHERE
profile_comments.profile_userid =  $user_id
ORDER BY
profile_comments.`timestamp` DESC");

            $this->load->library('form_validation');
            $this->form_validation->set_error_delimiters('<span class="system negative">',
                '</span>');
            $this->form_validation->set_rules('comment', 'Comment',
                'required|trim|min_length[4]|max_length[2500]');

            if ($this->form_validation->run() == false) {

                //Add Count to User Profile View
                $this->Counter->profileviewcounter($data['userquery']->id, $data['userquery']->
                    profile_views);

                $this->load->view('includes/header');
                $this->load->view('profiles/home', $data);
                $this->load->view('includes/footer');

            } else {

                //Add Comment
                $this->profile_functions->addcomment($user_id, $this->input->post('comment'));

            }

        }

    }
    
    function videos()
    {
        //Get User ID
        $user_id = $this->profile_functions->usernamechk($this->uri->segment(1));
        
        print 'Videos Pages<br>';
        print $user_id;
    }

this is not going to be the finial version of this controller. just put something together as i'm trying to get it to work correctly. will tidy it up when things are in order.
#4

[eluser]TheFuzzy0ne[/eluser]
What's the name of the controller?
#5

[eluser]Latavish[/eluser]
sorry my friend

the name of the controller is : profiles (profiles.php)
#6

[eluser]TheFuzzy0ne[/eluser]
Of course. That was clear from your first post... Sorry.

Code:
&lt;?php
function _validate_request($segments)
{
    // Does the requested controller NOT exist?
    if (!file_exists(APPPATH.'controllers/'.$segments[0].EXT))
    {
        $method = 'main';
        
        if(isset($segments[1]) && $segments[1] == 'video')
        {
            $method = 'video';
        }
        $segments = array("profiles", $method, $segments[0]);
    }
        
    return parent::_validate_request($segments);
}

There's probably a neater way to do this, but this should work.
#7

[eluser]Latavish[/eluser]
oh wow. that seemed to work like a charm. with just one error i'm getting. on line 17 which is

"if($segments[1] == 'video')"

i seem to get this error message.

Code:
Message: Undefined offset: 1
Filename: libraries/My_Router.php
Line Number: 17

of course i could supress the error by doing "if(@$segments[1] == 'video')" but ya know i would rather much try to fix the problem. ;-)

Thanks a million for all your help!
#8

[eluser]TheFuzzy0ne[/eluser]
Whoops. That was a silly error. I've corrected the code in my previous post.
#9

[eluser]Latavish[/eluser]
excellent!! that worked like a charm!! Thanks a million for all your help kind sir!!!

going to post some screen shots when this project is complete! Actually my first HUGE CI project.. thanks again for all your help.

and the coding continues......
#10

[eluser]TheFuzzy0ne[/eluser]
[quote author="Latavish" date="1237938771"]going to post some screen shots when this project is complete![/quote]

Looking forward to it. Good luck! Smile




Theme © iAndrew 2016 - Forum software by © MyBB