Welcome Guest, Not a member yet? Register   Sign In
Redirect loop
#5

[eluser]dmol[/eluser]
Yes, the original problem is that when someone clicks on a link in the menu, it calls a function in the controller which loads the appropriate view. Unfortunately this view is appended to the current page. I'm going to rebuild the controller so that is uses redirects to a function for each page. I have tried methods similar to your solution above but I think I have some scope of variables problem which maybe you can spot:

Basically I store all data into an array called $data which is not being seen by all functions.It should work but I don't know if its a PHP version issue - I'm using 4.3.9 but will upgrade to v5 soon. The controller has the following format:

CI routes.cfg sets 'main.php' as the default controller


This controller DOES NOT work as the functions cannot see $this->data;
class Main extends Controller {

var $data = 0;
function Main()
{
parent::Controller();
}
function index()
{
//Do essential startup stuff and store results in $this->data
if ($this->uri->segment(1))
{
redirect($this->uri->segment(1));
}

}
function page1() //E.g a function for each doc to display. not ideal but is temporary

{
$this->load->view("page1",$this->data);
}


The following format DOES WORK I.E $this->data is seen by all functions but since Main is not loaded on startup, none of its essential tasks are done and the page load is incomplete. This is why I want to load Main's code in index()

class Main extends Controller {

var $data = 0;
function Main()
{
parent::Controller();

//Do essential startup stuff and store results in $this->data
if ($this->uri->segment(1))
{
redirect($this->uri->segment(1));
}

} //end of main
function page1() //E.g a function for each doc to display. not ideal but temporary
{
$this->load->view("page1",$this->data);
}

I hope this is clear. Thank for your help!


Messages In This Thread
Redirect loop - by El Forum - 02-16-2011, 12:55 PM
Redirect loop - by El Forum - 02-16-2011, 02:17 PM
Redirect loop - by El Forum - 02-17-2011, 08:47 AM
Redirect loop - by El Forum - 02-17-2011, 03:22 PM
Redirect loop - by El Forum - 02-18-2011, 12:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB