In the same controller i have found there are two ways to redirect.
Class Home extends mY_Controller{
public $view;
public $redirect;
function first_method
{
$this->view = FALSE;
// $this->second_method();
// redirect('Home/second_method');
}
function second_method()
{
echo 'Second one';
}
}
I want to know which is the best approach also
i have a redirect method in the my_controller
if certain conditions do not match redirect the user using redirect variable
just for simplicity i am posting this
<?php
class MY_Controller extends CI_Controller
{
protected $data;
function __construct()
{
parent::__construct();
}
public function _remap($method, $parameters)
{
if($this->view === FALSE)
{
redirect($this->redirect);
}else{
$this->load->view('my_view');
}
}
}
Using the first method i am unable to access the second line
I suggest using
redirect()as it’s easy to change HTTP response code later, if you will need it, as well as making some of them to berefreshtype.You can always override the helper if you’ll find it necessary to change all your redirects later and you’ll even have ability to add some logic to them.