Welcome Guest, Not a member yet? Register   Sign In
_remap() when is the best time to use it?
#1

[eluser]anna16[/eluser]
Hi guys

When i review the manual regarding the controller topic, I noticed this built in __remap() method.
May i know when is the best time to use this method?

Thanks in advanced.
#2

[eluser]wiredesignz[/eluser]
Generally the second segment of the URL determines which controller method is called, but, if you use _remap you can intercept the call and it becomes another level of routing with more intelligent usage.

If however you create a base controller class using _remap it gives your application much more potential like so.

Code:
class BaseController extends ACL_Controller
{
    public $user;
    
    function __construct()
    {
        parent::__construct();
        
        $this->load->plugin(array('twig','form','widget'));
        
        //$this->output->enable_profiler();
    }    
    
    function _remap($method)
    {
        $data =& $this->load->_ci_cached_vars;
        
        $data['page']    = strtolower(get_class($this));
        $data['method'] = $method;
        
        if (method_exists($this, $method))
        {
            if ( ! $this->acl_error)
            {
                call_user_func_array(array($this, $method), array_slice($this->uri->segments, 2));
            }
        }
        else
        {
            show_404();
        }
                    
        if (request_is_ajax()) return;
        
        $view = new mxView();
        $data['widget'] = new mxWidget();
        $this->output->final_output = $view->load('layout.tpl', $data, TRUE);
    }
}
#3

[eluser]anna16[/eluser]
@wiredesignz

I'll try to comprehend your codes.
Thanks
#4

[eluser]wiredesignz[/eluser]
Just realize that _remap gives you much finer control over your application.
#5

[eluser]tonanbarbarian[/eluser]
to put it simply there are 2 common uses of remap

1. to authenticate that the user is allowed to perform the desired actions

2. to redirect the user to a completely different action than the one they chose

i am sure there are other uses as well but these are the 2 that i have used it for commonly




Theme © iAndrew 2016 - Forum software by © MyBB