Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Beginning PHP and MySQL E-commerce Plugin Error
Goto page 1, 2, 3  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Mon Mar 17, 2008 5:27 pm    Post subject: Beginning PHP and MySQL E-commerce Plugin Error Reply with quote

I'm currently going through the PHP 5 and MySQL E-Commerce tutorial and have encountered what appears to be an error. In chapter 3 page 85 the following line of code is causing the problem: {load_departments_list assign="departments_list"}

When I try to load the index.php file in the browser I get the following error message:
unrecognized tag 'load_departments_list' (Smarty_Compiler.class.php, line 590)

This is only a small part of the error message. I looked at line 590 of the Smarty.class.php and it states that the method 'assign' should take two arguments. I'm working locally and then uploading to a Web Server. The Web Server is running PHP ver 5.2.5 and I made the newest versions of the smarty and PEAR libraries available.

I have seen that within this forum other people have had the same problem, even though they are running PHP 5.0. As yet it seems it has gone unresolved.

I would appreciate any help you could provide, as I'm new to Smarty.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Mar 17, 2008 5:43 pm    Post subject: Reply with quote

load_departments_list is a user defined tag. It must be defined by a plugin in SMARTY's plugin directory or as a registered function in the application script.
Back to top
View user's profile Send private message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Mon Mar 17, 2008 6:15 pm    Post subject: I have smarty plugin function in smarty_plugins directory Reply with quote

I've defined a smarty function called:
smarty_function_load_departments_list() that's contained in the file function_load_departments_list.php. This PHP file resides within the smarty_plugins directory.

The code for the function within function_load_departments_list.php is the following:
// plugin functions inside plugin files must be named: smarty_type_name
function smarty_function_load_departments_list($params, $smarty)
{
$departments_list = new DepartmentsList();
$departments_list->init();

// assign template variable
$smarty->assign($params['assign'], $departments_list);
}

The file departments_list.tpl has the line that causing all the problems:
{load_departments_list assign='departments_list'}

As for registering the plugin function I'm not clear about.

Thanks for your help.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Mar 17, 2008 6:20 pm    Post subject: Reply with quote

Your file name is wrong. It must be function.load_departments_list.php
Back to top
View user's profile Send private message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Mon Mar 17, 2008 6:58 pm    Post subject: Reply with quote

Yes, sorry that was a mistype. The file is in fact named function.load_departments_list.php.

Thanks again.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Mar 17, 2008 7:17 pm    Post subject: Reply with quote

I can't reproduce the error at my place.

Just detected another error. The Smarty object must be passed by reference.

function smarty_function_load_departments_list($params, &$smarty)
Back to top
View user's profile Send private message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Mon Mar 17, 2008 7:25 pm    Post subject: Passed smarty parameter by reference Reply with quote

I have modified the code and passed the smarty parameter by reference and still have the same error.

You can view the full error at: http://www.softwhiz.co.uk/tshirtshop

Thanks.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Mar 17, 2008 8:02 pm    Post subject: Reply with quote

SMARTY can't access the plugin file.

Does $smarty->plugins_dir point to the right folder? The default for the Smarty plugins folder should be array('plugins').

Cross check the file name once again....

Otherwise I have no idea.
Back to top
View user's profile Send private message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Mon Mar 17, 2008 8:40 pm    Post subject: plugins_dir pointing to 2 different folders Reply with quote

I have smarty->plugins_dir pointing to the plugins directory and smarty_plugins. This is setup within the include directory in the file setup_smarty.php.

The following is some of the code in this file:
// class that extends Smarty, used to process and display Smarty files
class Page extends Smarty
{
// constructor
function _construct()
{
// Call Smarty's constructor
$this->Smarty();

// Change the default template directories
$this->template_dir = TEMPLATE_DIR;
$this->compile_dir = COMPILE_DIR;
$this->config_dir = CONFIG_DIR;
$this->plugins_dir[0] = SMARTY_DIR.'plugins';
$this->plugins_dir[1] = SITE_ROOT."/smarty_plugins";
}
}

Thanks
Back to top
View user's profile Send private message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Mon Mar 17, 2008 9:38 pm    Post subject: plugin file may have been in wrong directory Reply with quote

I have placed the function.load_departments_list.php file in the smarty plugins directory and now I'm getting a different error message. The error is PHP based and not smarty like the previous one. Probally smarty was only looking in the plugins directory for the file. I'll let you know when I've fully resolved the problem.

Thanks for your help.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Mar 17, 2008 9:42 pm    Post subject: Reply with quote

I think SITE_ROOT."/smarty_plugins" must be an absolute path. Is this the case?
Back to top
View user's profile Send private message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Mon Mar 17, 2008 9:57 pm    Post subject: Is Absolute Path Reply with quote

Yes, SITE_ROOT./"smarty_plugins" is absolute path. The SITE_ROOT is defined within config.inc.php and is equivalent to: http://www.softwhiz.co.uk/tshirtshop

In the config.inc.php file this is the code that defines it:
// SITE_ROOT contains the full path to the tshirtshop folder
define("SITE_ROOT", dirname(dirname(_FILE_)));

Thanks
Back to top
View user's profile Send private message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Mon Mar 17, 2008 10:13 pm    Post subject: The dirname(dirname(_FILE_)) function Reply with quote

I would like to clarify that the config.inc.php file is in the include directory just above the root tshirtshop. The dirname(_FILE_) method returns the parent directory of current file, which is include. dirname(dirname(_FILE)) returns the parent directory of include, which is tshirtshop. Therefore SITE_ROOT is http://www.softwhiz.co.uk/tshirtshop
Back to top
View user's profile Send private message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Tue Mar 18, 2008 12:32 am    Post subject: Finally Resolved The Problem Reply with quote

The problem was that the book PHP 5 and MySQL E-Commerce states that the plugin file function.load_departments_list.php should go into smarty_plugins. This is not the default directory that smarty looks for plugins. You should be able to specify an alternative directory for smarty to find the plugins. This was attempted with the following lines of code:

$this->plugins_dir[0] = SMARTY_DIR.'plugins';
$this->plugins_dir[1] = SITE_ROOT."/smarty_plugins";

Smarty didn't attempt to find the file within SITE_ROOT."/smarty_plugins" and therefore the result was an unrecognized tag error message. The plugin file should go into the default libs/smarty/plugins directory.

This should be kept for future reference for others who have the same problem. You can see at www.softwhiz.co.uk/tshirtshop that everthing is working fine.

Thanks for your help U.Tews.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Mar 18, 2008 12:43 am    Post subject: Reply with quote

Smarty is looping over the plugin directories. So I still suspect a problem with the SITE_ROOT path.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP