ricky spires Posted February 1, 2012 Share Posted February 1, 2012 hello. how can i code this so that if the page is an admin page i get the admin template and if the page is a public page i get the public template i seem to be having trouble with my function and if statements this is the code //$layout gets the header.php and the footer.php function include_layout($layout){ //this part find all pages Zone. zone is either Admin or Public $pageZone = Pages::find_all(); foreach ($pageZone as $pageZones){ $Pzone = $pageZones->zone; } //this part gets the template id that is set for admin and public $tempBS = BasicSettings::find_by_id(1); $atID = $tempBS->adminTemp_id; $ptID = $tempBS->publicTemp_id; // if page is admin get the admin template if ($pZone = "admin"){ $Atemp = Templates::find_adminTemp($atID); $ATname = $Atemp->name; include(TEMP.DS.$ATname.DS.'layouts'.DS.$layout); } // if page is public get the public template if($pZone = "public"){ $Ptemp = Templates::find_publicTemp($ptID); $PTname = $Ptemp->name; include(TEMP.DS.$PTname.DS.'layouts'.DS.$layout); } } to help you understand what im doing i have put a // description above each part of code. the problem is that i get the header echoed out twice. if i change the if to an if else like this... if ($pZone = "admin"){ $Atemp = Templates::find_adminTemp($atID); $ATname = $Atemp->name; include(TEMP.DS.$ATname.DS.'layouts'.DS.$layout); }else if($pZone = "public"){ $Ptemp = Templates::find_publicTemp($ptID); echo $PTname = $Ptemp->name; include(TEMP.DS.$PTname.DS.'layouts'.DS.$layout); } i only get 1 header but the public template does not work template this is because if i echo out echo $PTname = $Ptemp->name; i get nothing so. how can i code it so that if the page is an admin page i get the admin template and if the page is a public page i get the public template thanks ricky Quote Link to comment https://forums.phpfreaks.com/topic/256174-need-help-getting-the-correct-template-please/ Share on other sites More sharing options...
Proletarian Posted February 1, 2012 Share Posted February 1, 2012 I think you are overwriting your $Pzone variable every time. The logic here is not right. //this part find all pages Zone. zone is either Admin or Public $pageZone = Pages::find_all(); foreach ($pageZone as $pageZones){ $Pzone = $pageZones->zone; // <---- !!! } Also... You are using "=" instead of "==" to check for conditions. What you are doing instead is overwriting your variables you are checking. Fix those and your conditions will work correctly. Quote Link to comment https://forums.phpfreaks.com/topic/256174-need-help-getting-the-correct-template-please/#findComment-1313248 Share on other sites More sharing options...
ricky spires Posted February 1, 2012 Author Share Posted February 1, 2012 thankyou for your reply. im not sure how else to get the page zone other that using $pageZone = Pages::find_all(); foreach ($pageZone as $pageZones){ $Pzone = $pageZones->zone; // <---- !!! } i tried changing = to == and i get a blank white page if i change the code to this (see below) i still get a blank white page but it echos out template1template2 template1template2 //FIND ADMIN HEADER & FOOTER LAYOUT function include_layout($layout){ $pageZone = Pages::find_all(); foreach ($pageZone as $pageZones){ $Pzone = $pageZones->zone; } $tempBS = BasicSettings::find_by_id(1); $atID = $tempBS->adminTemp_id; $ptID = $tempBS->publicTemp_id; $Atemp = Templates::find_adminTemp($atID); echo $ATname = $Atemp->name; $Ptemp = Templates::find_publicTemp($ptID); echo $PTname = $Ptemp->name; if ($pZone == "admin"){ include(TEMP.DS.$ATname.DS.'layouts'.DS.$layout); }elseif($pZone == "public"){ include(TEMP.DS.$PTname.DS.'layouts'.DS.$layout); } } if i change the above code so its using = and not == it echoes out template1template2 PAGE TITLE=Temp1 - Admin Control Panel template1template2 the top "template1template2" is the header the bottom "template1template2" is the footer Quote Link to comment https://forums.phpfreaks.com/topic/256174-need-help-getting-the-correct-template-please/#findComment-1313262 Share on other sites More sharing options...
ricky spires Posted February 1, 2012 Author Share Posted February 1, 2012 FIXED IT //FIND ADMIN HEADER & FOOTER LAYOUT function include_layout($layout, $pageID){ $pageZone = Pages::find_by_pageID($pageID); foreach ($pageZone as $pageZones){ $Pzone = $pageZones->zone; } //echo public or admin $tempBS = BasicSettings::find_by_id(1); $atID = $tempBS->adminTemp_id; //12 $ptID = $tempBS->publicTemp_id; //12 if ($Pzone=="admin"){ echo "admin"; $Atemp = Templates::find_adminTemp($atID); $ATname = $Atemp->name; //template1 include(TEMP.DS.$ATname.DS.'layouts'.DS.$layout); }else if($Pzone=="public"){ echo "public"; $Ptemp = Templates::find_adminTemp($ptID); $PTname = $Ptemp->name; //template2 include(TEMP.DS.$PTname.DS.'layouts'.DS.$layout); } } i have the capitals in the wrong place here = $Ptemp . i had it as $pTemp also i needed to change this $pageZone = Pages::find_all(); foreach ($pageZone as $pageZones){ $Pzone = $pageZones->zone; } to only find the current page and not all. $pageZone = Pages::find_by_pageID($pageID); foreach ($pageZone as $pageZones){ $Pzone = $pageZones->zone; } //echo public or admin thanks Quote Link to comment https://forums.phpfreaks.com/topic/256174-need-help-getting-the-correct-template-please/#findComment-1313357 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.