rootKID Posted October 7, 2013 Share Posted October 7, 2013 Hey again. I once again stuck with a problem, or more likely a question of a sort. I am trying to build my own sort of API/Coding system, if you could call it that. In other words, a more easier way of creating controlled websites by me (guess that is the closes thing i could come to an explanation). Right now i am working on a template system that would allow me to controle what files (codes) to be loaded on each page the current user now are on. This means if the user uses a template called dark_v1, it will then go into the folder (pages) and from there go into the folder called dark_v1. Now, in there i will have seperated folder, like home,webshop, etc. On each folder i will have a file called (page_controller.php). Very simple, it will hold the array i will need to use later on. Here is example: array('news' => 'news','last_forums_posts' => 'last_forums_posts','last_forums_replies' => 'last_forums_replies'); This peace of code, will allow me to easily write in the array what files to take from the current location. This will come in handy in my own experience, even tho it is still not working, but the purpose is clear in my own eyes. Now, on index.php file (also known as home-page), i would like to make an foreach statement, and will then load the current files that are IN that current loaded array from the (home) directory/folder. Here is my current example and that i am working on: require_once("include/core.php");get_template();$HTMLOUT = "";//Starting Variable...//$files = array('news' => 'news', 'last_forums_replies' => 'last_forums_replies', 'last_forums_posts' => 'last_forums_posts');$folder_url = "home";$HTMLOUT .= "<br />";$files = array(include("pages/".$LH['template']."/".$folder_url."/page_controller.php"));foreach($files as $file_id => $file){ include_once("pages/".$LH['template']."/".$folder_url."/{$file}.php"); $HTMLOUT .= "<br />";} //$HTMLOUT .= "123";print stdhead('Home') . $HTMLOUT . stdfoot(); As you see, i used the array on the index.php file itself a while ago. And guess what, it worked. But now when i try to do it this way, it will not work. And i simply and easy needs a new set of eyes on my little project here. Hoping your dudes and girlz out there can spot something i cannot, and hope you understand the project i am doing right now. If not, do not hesitate to comment. I will try to explain more in details if possible so you can understand it. Thanks... ALOT! if you could spot something i could not! -rootKID Link to comment Share on other sites More sharing options...
Ingolme Posted October 7, 2013 Share Posted October 7, 2013 Just set the array in the included file, then you can work with it normally: a.php $files = array( 'a' => 1, 'b' => 2); b.php include 'a.php';echo $files['a']; Link to comment Share on other sites More sharing options...
justsomeguy Posted October 7, 2013 Share Posted October 7, 2013 $files = array(include("pages/".$LH['template']."/".$folder_url."/page_controller.php")); Unless you are returning the array from that include file, that line is going to make $files an array with the value "1" in it and nothing else. An include statement will evaluate to 1 unless the included file contains a return statement returning another value. http://www.php.net/manual/en/function.include.php Link to comment Share on other sites More sharing options...
rootKID Posted October 7, 2013 Author Share Posted October 7, 2013 Ohh.. did not see that one coming :/. Thanks! Will test your method tomorrow Ingolme, currently i have some visitors at my home. Will reply tomorrow if it worked! Link to comment Share on other sites More sharing options...
rootKID Posted October 8, 2013 Author Share Posted October 8, 2013 (edited) Ingolme: I tried to implent you method last night to my foreach element on index.php file. And i got an error again, this is my example: Index.php: require_once("include/core.php");get_template();$HTMLOUT = "";//Starting Variable...$folder_url = "home";$HTMLOUT .= "<br />";include("pages/".$LH['template']."/".$folder_url."/page_controller.php");foreach($files as $file_id => $file){ include_once("pages/".$LH['template']."/".$folder_url."/{$file}.php"); $HTMLOUT .= "<br />";}print stdhead('Home') . $HTMLOUT . stdfoot(); page_controller.php: $files = array('news' => 'news','last_forums_posts' => 'last_forums_posts','last_forums_replies' => 'last_forums_replies'); Any ideas/clues of how to fix Oo.. I mean, it should be working correctly in my own eyes. I included the file with the variable ($files) containing the array information, and used that variable on index.php file. Should that not do the trick? Oo EDIT: Currently in school right now, so cannot tell you the error. But will check when i get home later, to see if i can find the error again -rootKID Edited October 8, 2013 by rootKID Link to comment Share on other sites More sharing options...
justsomeguy Posted October 8, 2013 Share Posted October 8, 2013 Make sure the include file has PHP tags in it. Link to comment Share on other sites More sharing options...
rootKID Posted October 8, 2013 Author Share Posted October 8, 2013 Sorry for late reply, and it has php start and end tags in it.. that is kind of the purpose here hehe ... But i still dont understand why it makes such a scene about the damn coding.. should be working just fine as i can see it... i simply dont understand -.-' Link to comment Share on other sites More sharing options...
justsomeguy Posted October 8, 2013 Share Posted October 8, 2013 I don't know what error you're seeing, but I don't see anything obviously wrong. Link to comment Share on other sites More sharing options...
rootKID Posted October 9, 2013 Author Share Posted October 9, 2013 (edited) I keep get this error: Parse error: syntax error, unexpected 'foreach' (T_FOREACH) in C:xampphtdocsother_projectslh_v1index.php on line 8 and this is my HOLE code in the 2 files: Index.php: <?phprequire_once("include/core.php");get_template();$HTMLOUT = "";//Starting Variable...$folder_url = "home";$HTMLOUT .= "<br />";include("pages/".$LH['template']."/".$folder_url."/page_controller.php")foreach($files as $file_id => $file){ include_once("pages/".$LH['template']."/home/{$file}.php"); $HTMLOUT .= "<br />";}print stdhead('Home') . $HTMLOUT . stdfoot();?> page_controller.php: <?php$files = array('news' => 'news','last_forums_posts' => 'last_forums_posts','last_forums_replies' => 'last_forums_replies');?> and they are 110% exact as shown above here... i just dont get it... Edited October 9, 2013 by rootKID Link to comment Share on other sites More sharing options...
Ingolme Posted October 9, 2013 Share Posted October 9, 2013 You forgot to end line 7 with a semi-colon ; Link to comment Share on other sites More sharing options...
rootKID Posted October 9, 2013 Author Share Posted October 9, 2013 I found out when i got home today, lol.. feeling like a rookie. Hate when i forget some damn small thing in the coding like this one But thanks anyways! Got it working now! Link to comment Share on other sites More sharing options...
justsomeguy Posted October 9, 2013 Share Posted October 9, 2013 That's what error messages are for. When it tells you that there is a parse error on line 8, most people immediately check line 7. Link to comment Share on other sites More sharing options...
rootKID Posted October 21, 2013 Author Share Posted October 21, 2013 lol haha.. yeah, still learning ... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now