Page 1 of 1

How to change directory when using a classtemplate

Posted: Mon Sep 26, 2016 10:29 am
by hybris
Hello again,

I use a class to help me with the layout of my homepage. To the left I have buttons that redirect to various php script (pages). Those are displayed in the main column on my page.

The mainpage class is stored in Framework_Lib.php and before I had all the pages in the same folder as Framework_Lib.php and it all worked fine.

The problem is there are so many files now so I wanted to move the pages the buttons point to to a subfolder called Leftmenu.

Now it only works the first time I click a button but after that all the links are broken since i jump from /Main folder (where the class is stored) to /Main/Leftmenu/

The way the page is setup is i make an array with the buttons and the url like $buttons = array ("Show Users" => "/../Main/Leftmenu/users.php");
In users I use
ob_start();
Code here
$content=ob_get_contents();
ob_end_clean();
$homepage->content = $content;
$homepage->Display();

So it all works fine when all the content is in the same folder but as soon as i put stuff in another folder it ofcourse breaks since my button array redirect to another folder.. but is there a way to get back to redirect back to the Main folder from the users.php page?

Re: How to change directory when using a classtemplate

Posted: Mon Sep 26, 2016 10:33 am
by Celauran
Is your Framework_Lib basically just doing an include of that page? You could set a variable as a base path so you can load things relative to its location. Really, though, feels like there's some reinventing of the wheel going on here. Any reason you're not using an existing router and something like Twig for templating?

Re: How to change directory when using a classtemplate

Posted: Mon Sep 26, 2016 10:49 am
by requinix
The browser won't go into the Leftmenu "directory" unless you tell it to in a link.

Re: How to change directory when using a classtemplate

Posted: Mon Sep 26, 2016 11:09 am
by hybris
Is your Framework_Lib basically just doing an include of that page?
Yeah. The Framework_lib just defines the layout and a row with top buttons and leftside buttons and what background imges to use in the different divs.
Really, though, feels like there's some reinventing of the wheel going on here.
I like wheels :D No the page is working fine as long as i dont try to put the files the menubuttons point to in a different folder.
Any reason you're not using an existing router and something like Twig for templating?
Well I want to learn and know what Im doing, also havent heard bout Twig before. But my template work fine if i just leave the files in the same folder. Was just curious if there were an easy fix like chdir() or something to jump back.
The browser won't go into the Leftmenu "directory" unless you tell it to in a link.
I do tell it to go there in the buttons array.. Was curious if there were any easy way to go back :)

Re: How to change directory when using a classtemplate

Posted: Mon Sep 26, 2016 11:50 am
by hybris
$root = realpath($_SERVER["HTTP_HOST"]);

Think that solved my problem...atleast with the links but now my graphics is screwed up... Fix 1 thing and break 2 other things heh

Re: How to change directory when using a classtemplate

Posted: Mon Sep 26, 2016 12:32 pm
by Celauran
Have you tried what I suggested earlier? Define your templates path in and relative to your Framework_Lib and use that to get the full path to use in your includes, rather than trying to juggle relative paths.

Re: How to change directory when using a classtemplate

Posted: Mon Sep 26, 2016 1:41 pm
by hybris
I have some systems in earlier catalogues than the framework so I used $root = realpath($_SERVER["HTTP_HOST"]);
and $root = realpath($_SERVER["DOCUMENT_ROOT"]); instead and it worked like a charm.

Reason the graphics ddnt work was i forgot to update the img path but now it all works again :)

Thanks :)