Jump to content

need help getting the correct template please


ricky spires

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.