Welcome Guest, Not a member yet? Register   Sign In
Troubles with routing
#1

[eluser]IEDani[/eluser]
Hi,
I am a begginer with code Igniter and I am lost with the routing rules.

I´d like to include some parts of code, something so tipical. For example, I have in the folder views the file x.php, in this file I want to include the file foot.php (that is in a folder called includes, that is contain in views folder).

I think that I have to put in x.php file include("includes/foot.php") or include("./includes/foot.php"), but it doesn´t work.

If I put the absolute routes ir works good, but I prefer relative routes, do you knows how can include files with relative routes?

Thanks you,
Dani
#2

[eluser]n0xie[/eluser]
Maybe you should try to use views instead of includes?

In your view:

Code:
$this->load->view('header');

/* your view */

$this->load->view('footer');
#3

[eluser]IEDani[/eluser]
sure? I can´t use traditional routing system? Anyway, thanks a lot!
Besides, if I have a form and I want to put the destination page, I have to put the absolute route, can I use relative routes? How?
#4

[eluser]n0xie[/eluser]
What do you mean by destination page?

If you mean the page your form submits to, then that should be to a controller. In that case you wouldn't use relative or absolute paths, you would use the URL. Something like http://www.mysite.tld/mycontroller/funct...tosubmitto.

If you mean you want to include a form then the usual way to go about it, is to load the view in the controller like this:
Code:
/* controller */
$pagecontent['form1'] = $this->load->view('myform',$data,TRUE);
Now the output is stored in a string or object instead of outputted to the browser. You can now pass it to your (master) template like this:

Code:
/* controller */
$this->load->view('mytemplate',$pagecontent);

Inside your template_view you can then output it like you would any other string/object:
Code:
/* my template_view */
$this->load->view('header');

echo $form1;

$this->load->view('footer');
This way, if you ever change the layout of your form, it will automatically be adjusted for any page you use the same form...

Hope that helps...




Theme © iAndrew 2016 - Forum software by © MyBB