• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with constructor and URI

#1
[eluser]v1ctoria[/eluser]
Hi lads!

I'm actually building a simple website with members and I wanted to display member's page by just calling www.mywebsite.com/member/membername

My class member is actually working well, but I had put the code in the index function making page member accessible at www.mywebsite.com/member/index/membername, which is actually not really useful.

So the classic things was to put my code in the constructor, but I get the error :
Quote:404 Page Not Found
The page you requested was not found.

This is my class Member :
Code:
<?php

class Member extends CI_Controller {

    
    function __construct()
    {
           parent::__construct();


           $segment_id = $this->uri->segment(2, 0);
           echo 'segment found ='.$segment_id;
           if ($segment_id == FALSE)
            {
                   echo '- No Segment -> Printing all members ';
                   $data = array();
                   $this->layouts->set_title('Welcome!');

                   $this->layouts->add_aside('newsletter_view');

                   if($query = $this->membership_model->show_all())
                    {
                        $data['records'] = $query;
                    }

                    $this->layouts->view('show_member', $data);
            }
            else
            {
                    echo '- Segment found -> Printing the member ';
                    $data = array();
                    $this->layouts->set_title('Welcome!');

                    $this->layouts->add_aside('newsletter_view');

                    if($query = $this->membership_model->show_member())
                    {
                            $data['records'] = $query;
                    }

                    $this->layouts->view('show_member', $data);
            }

    }

}

And to complete, this is my model function:
Code:
function show_member()
    {
                echo 'model show_member working';
        $this->db->where('username', $this->uri->segment(2));
        $query = $this->db->get('members');

                return $query->result();
    }

        function show_all()
        {
                echo "model show_all working";
                $query = $this->db->get('members');
        return $query->result();
        }


You will find some echo into. All are perfectly working going with a url with /member or /member/segment and as I sad, all is working if I'm putting it in Index


Thanks a lot for your help


Messages In This Thread
Problem with constructor and URI - by El Forum - 04-27-2011, 11:07 AM
Problem with constructor and URI - by El Forum - 04-27-2011, 11:26 AM
Problem with constructor and URI - by El Forum - 04-27-2011, 11:38 AM
Problem with constructor and URI - by El Forum - 04-27-2011, 12:21 PM
Problem with constructor and URI - by El Forum - 02-11-2012, 09:52 PM
Problem with constructor and URI - by El Forum - 02-11-2012, 11:15 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.