Welcome Guest, Not a member yet? Register   Sign In
Using redirect() ?
#1

[eluser]chefnelone[/eluser]
Hello,

I just can't redirect to other function and stop in that function.

When the site is loaded is routed to load index/index. So far so good.
Then I'like to redirect in the __construct function so that if the var $in_construction is set to 'yes' it should be redirect to the in_construction function.

Below what I've done, this code make the redirection but it ALSO execute the index function. I mean it execute the line:
Code:
$this->load->view('in_construction');
BUT ALSO EXECUTE THE LINE:
Code:
$this->load->view('index');
.
What I need is just to run the in_construction function but not the index function
Code:
class Index extends MY_Controller {

function __construct(){
     parent::__construct();
     $in_construction ='yes';
     if($in_construction =='yes'){
           redirect('index/in_construction');
     }    
} //CLOSE __construct


function in_construction(){
     $this->load->view('in_construction');
}

function index(){
     $this->load->view('index');
}

} //CLOSE class
#2

[eluser]InsiteFX[/eluser]
Code:
class Index extends MY_Controller {

function __construct(){
     parent::__construct();
     $in_construction ='yes';
} //CLOSE __construct

function index(){
     if($in_construction =='yes'){
           $this->load->view('in_construction');
     }
     else {    
           $this->load->view('index');
     }
}

} //CLOSE class

I would implement away to set the $in_construction variable!
It should not be hard coded into the constructor.

InsiteFX
#3

[eluser]chefnelone[/eluser]
[quote author="InsiteFX" date="1285605531"]
Code:
class Index extends MY_Controller {

function __construct(){
     parent::__construct();
     $in_construction ='yes';
} //CLOSE __construct

function index(){
     if($in_construction =='yes'){
           $this->load->view('in_construction');
     }
     else {    
           $this->load->view('index');
     }
}

} //CLOSE class

I would implement away to set the $in_construction variable!
It should not be hard coded into the constructor.

InsiteFX[/quote]

I did what you say before, but the problem is that if I add a new functions I'll need to repeat the if sentence again and again. That's why I want to include it in the constructor...

It shouldn't be difficult to do it ...
#4

[eluser]InsiteFX[/eluser]
Use a MY_Contoller see the user guide.

InsiteFX
#5

[eluser]treeface[/eluser]
If you find yourself reusing a controller-specific variable or function repeatedly across multiple controllers, you might have found yourself a perfect opportunity to extend the base Controller class. See here for more information:

http://stackoverflow.com/questions/16263...ller-class




Theme © iAndrew 2016 - Forum software by © MyBB