custom tag giving error

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
ysf

custom tag giving error

Post by ysf »

i wrote a custom tag which retrieves a record from the databse and displays the content.
when i include this custom tag in template it gives me the following error:

Warning: smarty_cms_function_banner(../include.php) [function.smarty-cms-function-banner.html]: failed to open stream: No such file or directory in C:\htdocs\cmsmadesimple\plugins\function.banner.php on line 21

this is the code:

Code: Select all

<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

function smarty_cms_function_banner($params, &$smarty) {
	//code for displaying banner on top of the page
	require_once("../include.php");
	$result = $db->Execute("SELECT * FROM ".cms_db_prefix()."header where current=1");
	$row = $result->FetchRow();
	$banner_name = $row["name"];
	
	echo "<img src='http://localhost/cmsmadesimple/uploads/images/header/$banner_name'>";
}

?>

please somebody tell me what is the problem.....
Last edited by ysf on Mon Apr 25, 2005 3:40 pm, edited 1 time in total.
100rk

Re: custom tag giving error

Post by 100rk »

File 'include.php' is allways included, so You are doing duplicate thing. If You want to obtain initialized adodb connection from CMSMS in Your plugin, just write code

Code: Select all

global $gCms;
$db = & $gCms->db;
and that is it.
Last edited by 100rk on Mon Apr 25, 2005 3:46 pm, edited 1 time in total.
ysf

Re: custom tag giving error

Post by ysf »

thanx 100rk !!! it worked....
100rk

Re: custom tag giving error

Post by 100rk »

Not at all ;-)

By the way: try to use absolute paths in Your include and require commands - something like

Code: Select all

require_once dirname(dirname(__FILE__)).'/include.php';
This is true reason why Your plugin doesn't work.
Last edited by 100rk on Mon Apr 25, 2005 3:51 pm, edited 1 time in total.
ysf

Re: custom tag giving error

Post by ysf »

it might be silly to ask but what does __FILE__ do in require_once dirname(dirname(__FILE__)).'/include.php';
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: custom tag giving error

Post by Ted »

__FILE__ actually gets replaced with a string of the full path of the current file name.  dirname(__FILE__) returns the directory that the file is in.  dirname(dirname(__FILE__)) returns the previous directory and is pretty much equivilent to ..
Locked

Return to “CMSMS Core”