Search code examples
phpcodeignitercodeigniter-routing

i need pass variable in url using slash in codeigniter


I'm new for CodeIgniter.

My Controller is:

class User extends CI_Controller {

    function __construct() 
    {
        parent::__construct();
        $this->load->helper('form');
        $this->load->library('form_validation');
    }    


    public function index($user)
    {
        if($user != '')
        {
            if($this->session->userdata('user_id'))
            {
                echo 'user in';
            }
            else
            {
                redirect('/');
            }
        }
        else
        {
            echo 'wrong page';
        }
    }
}

1st of all i logged into this site. If i give url like http://localhost/picyou/user it show 'wrong page'...

If i give url like http://localhost/picyou/user/fh it show '404 Error'...

But I need to display "user in".

Help me...


Solution

  • If you want the URL to work you need to include the function name

    http://localhost/picyou/user/index/fh
    

    If you want to don't want to have index in the url then you need to look at URI routing