• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_remap() acting up

#1
[eluser]Samuurai[/eluser]
Hi everyone,

It's probably not acting up at all.. I probably just don't know the correct usage.

Here's my code:

Code:
function _remap()
    {
        if($this->uri->segment(3) == "create")
            $this->create();
        if($this->uri->segment(3) != "create" OR $this->uri->segment(3) != "view" OR $this->uri->segment(3) != "update" OR is_numeric($this->uri->segment(3)))
        {
            $this->index($this->uri->segment(3),$this->uri->segment(4),$this->uri->segment(5));
        }
        
    }
The only reason i'm using it is because I need to pass variables via the URI to the index() function. This works fine, but then all my other functions (create, view, update) don't work. They seem to go to index() instead.

I tried first ignoring them (see the long if statement). Then I tried the first if statement..both to no avail.

Can anyone spot any obvious flaws in my code?

Thanks

#2
[eluser]mah0001[/eluser]
From Docs: If your controller contains a function named _remap(), it will always get called regardless of what your URI contains. It overrides the normal behavior in which the URI determines which function is called, allowing you to define your own function routing rules.

Try this, you need to handle all cases in the remap:
Code:
function _remap()
    {
        //create
        if($this->uri->segment(3) == "create")
        {
            $this->create();
        }    

        //view
        if($this->uri->segment(3) == "view")
        {
            $this->view();
        }    
        
        //call to the index function
        if($this->uri->segment(3) != "create" && $this->uri->segment(3) != "view" && $this->uri->segment(3) != "update" && is_numeric($this->uri->segment(3)))
        {
            $this->index($this->uri->segment(3),$this->uri->segment(4),$this->uri->segment(5));
        }
        
    }

#3
[eluser]charlie spider[/eluser]
I use remap this exact same way but you will find that a switch will run better than a bunch of IF statements try:

Code:
function _remap()
{

    if ( isset( $this->uri->segment(3) ) )
    {
    
        switch ($this->uri->segment(3))
        {
            case 'create':
                $this->create();
            break;

            case 'view':
                $this->view();
            break;

            case 'update':
                $this->update();
            break;

            default:
                 $this->index($this->uri->segment(3),$this->uri->segment(4),$this->uri->segment(5));
            break;
        }

    }
        
}

#4
[eluser]Samuurai[/eluser]
That worked an absolute treat! I had to change
Code:
if ( isset( $this->uri->segment(3) ) )
to
Code:
if ( $this->uri->segment(3) )
Because it said I couldn't use return method in write context.

Thanks a lot both of you.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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