Page 1 of 1

custom tag giving error

Posted: Mon Apr 25, 2005 3:29 pm
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.....

Re: custom tag giving error

Posted: Mon Apr 25, 2005 3:42 pm
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.

Re: custom tag giving error

Posted: Mon Apr 25, 2005 3:46 pm
by ysf
thanx 100rk !!! it worked....

Re: custom tag giving error

Posted: Mon Apr 25, 2005 3:49 pm
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.

Re: custom tag giving error

Posted: Mon Apr 25, 2005 4:15 pm
by ysf
it might be silly to ask but what does __FILE__ do in require_once dirname(dirname(__FILE__)).'/include.php';

Re: custom tag giving error

Posted: Mon Apr 25, 2005 4:38 pm
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 ..