Jump to content

Problem with a tpl file I created.


Guest

Recommended Posts

Got a little stuck with a tpl and include file I created. Was wondering if anyone could shed some light as to where I have went wrong.

I get this error message :

Fatal error: Call to a member function on a non-object in /home/nas02l/o/outdoor-spirit.co.uk/user/htdocs/store/includes/boxes/bannerRight.inc.php on line 90

Here is the tpl file code :

<!-- BEGIN: banner_right -->

<div style="{VAL_BG_STYLE}" id="imgRight"></div>

<!-- END: banner_right -->




And here is the associated include file code :




<?php



	//////////////////////////

	// BANNER IMAGES RIGHT

	//////////////////////////

	

	if(isset($_GET['catId'])) { // category page

  switch($_GET['catId']){

 	 case 7:

 	 case 8:

 	 case 9:

 	 case 10:

 	 case 11:

 	 case 12:

 	 case 13:

 	 case 41:

 	 case 59:

 	 case 60:

    $imgRight = 'category_footwear_right.jpg';

    break;

 	 case 15:

 	 case 16:

 	 case 17:

 	 case 18:

 	 case 19:

 	 case 20:

 	 case 55:

    $imgRight = 'category_clothing_right.jpg';

    break;

 	 case 21:

 	 case 22:

 	 case 23:

 	 case 24:

    $imgRight = 'category_camping_right.jpg';

    break;

 	 case 25:

 	 case 26:

 	 case 27:

 	 case 28:

 	 case 29:

 	 case 30:

 	 case 50:

    $imgRight = 'category_accessories_right.jpg';

    break;

 	 case 31:

 	 case 32:

 	 case 33:

 	 case 34:

 	 case 35:

 	 case 36:

    $imgRight = 'category_fishing_right.jpg';

    break;

 	 case 37:

 	 case 38:

 	 case 39:

 	 case 42:

 	 case 56:

 	 case 57:

    $imgRight = 'category_country_clothing_right.jpg';

    break;

 	 case 43:

    $imgRight = 'category_skiing_right.jpg';

    break;

 	 case 44:

    $imgRight = 'category_walking_right.jpg';

    break;

 	 default:

    $imgRight = 'none';

    break;

  }

	

  if($imgRight=='none') {

 	 $bgStyle = "height:198px; background-image:none;";  

 	 $box_content->assign("VAL_BG_STYLE",$bgStyle);

  } else {

 	 $fileURL = "url(".$GLOBALS['rootRel']."skins/".$config['skinDir']."/styleImages/banners/".$imgRight.");";

 	 $bgStyle = "height:198px; background-image:".$fileURL."; background-position-x:top; background-repeat:no-repeat;";  

 	 $box_content->assign("VAL_BG_STYLE",$bgStyle);

  }

  

	} else if( (isset($_GET['act'])) && ($_GET['act']='viewProd') ) { // Product Page

  

  $bgStyle = "height:198px; background-image:none;";

  $box_content->assign("VAL_BG_STYLE",$bgStyle);

  

	} else { // hopefully just home page

	

  $fileURL = "url(".$GLOBALS['rootRel']."skins/".$config['skinDir']."/styleImages/banners/brochure_store_right.jpg);";

  $bgStyle = "height:198px; background-image:".$fileURL."; background-position-x:top; background-repeat:no-repeat;";  

  $box_content->assign("VAL_BG_STYLE",$bgStyle);

	

	}	

	

$box_content->parse("banner_right");

$box_content = $box_content->text("banner_right");

?>

Link to comment
Share on other sites

just to add:

 } else { // hopefully just home page



 $fileURL = "url(".$GLOBALS['rootRel']."skins/".$config['skinDir']."/styleImages/banners/brochure_store_right.jpg);";

 $bgStyle = "height:198px; background-image:".$fileURL."; background-position-x:top; background-repeat:no-repeat;";  

 $box_content->assign("VAL_BG_STYLE",$bgStyle); <--line 90



}

Link to comment
Share on other sites

Guest estelle

Although line 90 appears to match up with this line:

 $box_content->assign("VAL_BG_STYLE",$bgStyle);


i'm guessing that the actual problem is with the first attempt to use $box_content->assign(..).



It looks like you need to add this at the top of your bannerRight.inc.php. Don't forget to change YOURFILENAME to whatever it should be:


if(!isset($config)){

	echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";

	exit;

}



$box_content=new XTemplate ("skins/".$config['skinDir']."/styleTemplates/boxes/YOURFILENAME.tpl");

Link to comment
Share on other sites

Instead of your huge switch statement, why not put the image names into an array keyed on the catId?

You could do a static file somewhere like this:

<?php

$imgRight[24] = "category_camping_right.jpg";

$imgRight[55] = "category_clothing_right.jpg";

$imgRight[60] = "category_footwear_right.jpg";



... and so on ...

?>

Then in your current file, simply include this one and use $imgRight[$_GET['catId'])] to call values from it.

If you do this, it will be easier and cleaner to keep up with adding new images for categories.

Now personally, I'd have added a field to the database for the image for each category then pulled that at run time, but I realize not everybody thinks like me or is willing to muck about in their database and admin control panel. B)

Link to comment
Share on other sites

Thanks, I'll keep that in mind.

Might leave it till the site has gone live for a wee while.

*Update*

Must sort having a shopping cart box equivalent on the brochure side first, the session probs are doing my head in.

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...