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 Previous  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
bumbar
Smarty Rookie


Joined: 12 Jan 2007
Posts: 5

PostPosted: Mon Jun 16, 2008 8:22 am    Post subject: Reply with quote

Hallo!

I have the same problem! (from book ... E-commerce 2nd).

in file application.php I have line as It is written in the book:
Code:
$this->plugins_dir[1] = PRESENTATION_DIR . 'smarty_plugins';


But I have mistake:
ERRNO: 256
TEXT: Smarty error: [in department_list.tpl line 3]: [plugin] unknown tag - 'load_presentation_object'


It seems that smarty does not see the drive in the function...

Whats happen?
Back to top
View user's profile Send private message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Mon Jun 16, 2008 11:58 am    Post subject: Reply with quote

Could you specify the name of the plugin file and the complete header for the plugin function.

The plugin file name should be like the following:
function.load_department.php

The plugin header should be like the following:
function smarty_function_load_department($params, $smarty)
Back to top
View user's profile Send private message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Mon Jun 16, 2008 1:10 pm    Post subject: Reply with quote

If the problem is not the way you named the plugin file and plugin function then the following are possible causes.

1) Make sure you are using PHP 5. The author told me that these types of errors occur when using PHP 4.

2) If the name of the file is function.load_department.php and plugin function smarty_function_load_department($params, $smarty), then to make the plugin available to the template file department.tpl you load it this way:
{load_department assign="department"}

3) Try placing the plugin file in the default smarty plugins directory. This worked for me when I was having problems. When I removed the plugin file from the default plugins directory back into the smarty_plugins it started to work. This suggested that smarty was missing the smarty_plugins directory while looping through plugins_dir.
Back to top
View user's profile Send private message
bumbar
Smarty Rookie


Joined: 12 Jan 2007
Posts: 5

PostPosted: Mon Jun 16, 2008 1:55 pm    Post subject: Reply with quote

I changed the name of the plugin file function.load_department.php

and the name of the function accordingly smarty_function_load_department($params, $smarty)

But I have the same error

Here the directory tree as it is in the book:

Code:

/business
/images
/include
/libs/smarty
/presentation
        ./template
        ./template_c
/smarty_plugins
/styles



code snip

departments_list.tpl
Code:

{* departments_list.tpl *}
{load_department filename="departments_list" assign="obj"}
{* Start departments list *}
There be more code here


store_front.tpl
Code:

{* smarty *}
{config_load file="site.conf"}
{load_department file="store_front" assign="obj"}
There be more code here


/presentation/application.php
Code:

<?php
// Reference Smarty library
require_once SMARTY_DIR . 'Smarty.class.php';
/* Class that extends Smarty, used to process and display Smarty
files */
class Application extends Smarty   {
      // Class constructor
      public function __construct()   {

         // Call Smarty's constructor
         parent::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] = PRESENTATION_DIR . 'smarty_plugins';
   }
}
?>


/smarty_pluins/function.load_department.php
Code:

<?php
// Plug-in functions inside plug-in files must be named: smarty_type_name
function smarty_function_load_department($params, $smarty)
{
require_once PRESENTATION_DIR . $params['filename'] . '.php';
$className = str_replace(' ', '', ucfirst(str_replace('_', ' ',$params['filename'])));
// Create presentation object
$obj = new $className();
if (method_exists($obj, 'init'))
{
$obj->init();
}
// Assign template variable
$smarty->assign($params['assign'], $obj);
}
?>


I do not consider anymore that I can repair this problem ....
Back to top
View user's profile Send private message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Mon Jun 16, 2008 2:37 pm    Post subject: Reply with quote

How are the globals SMARTY_DIR and PRESENTATION_DIR definded. In the first book the global definitions were in config.inc.php.
Back to top
View user's profile Send private message
bumbar
Smarty Rookie


Joined: 12 Jan 2007
Posts: 5

PostPosted: Mon Jun 16, 2008 2:54 pm    Post subject: Reply with quote

my server uses PHP 5

Here config.php file

/include/config.php
Code:

// SITE_ROOT contains the full path to the tshirtshop folder
define('SITE_ROOT', dirname(dirname(__FILE__)));
// Application directories
define('PRESENTATION_DIR', SITE_ROOT . '/presentation/');
define('BUSINESS_DIR', SITE_ROOT . '/business/');
// Settings needed to configure the Smarty template engine
define('SMARTY_DIR', SITE_ROOT . '/libs/smarty/');
define('TEMPLATE_DIR', PRESENTATION_DIR . 'templates');
define('COMPILE_DIR', PRESENTATION_DIR . 'templates_c');
define('CONFIG_DIR', SITE_ROOT . '/include/configs');
Back to top
View user's profile Send private message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Mon Jun 16, 2008 3:06 pm    Post subject: Reply with quote

What is the error message you are getting now?

I won't be able to reply to your reply until later on this evening.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Mon Jun 16, 2008 3:14 pm    Post subject: Reply with quote

Your path is wrong.

Must be
Code:
         $this->plugins_dir[1] = SITE_ROOT. '/smarty_plugins';
Back to top
View user's profile Send private message
bumbar
Smarty Rookie


Joined: 12 Jan 2007
Posts: 5

PostPosted: Mon Jun 16, 2008 5:44 pm    Post subject: Reply with quote

I tried to move the file of plugin even The file folder of Smarty

/libs/smarty/plugins/function/function.load_presentation_object.php

and nothing.

Also I tried to modify

Code:

$this->plugins_dir[1] = PRESENTATION_DIR . 'smarty_plugins';

to
Code:

$this->plugins_dir[1] = SITE_ROOT. '/smarty_plugins';


And the same error:

Code:

ERRNO: 256
TEXT: Smarty error: [in store_front.tpl line 3]: syntax error: unrecognized tag 'load_presentation_object' (Smarty_Compiler.class.php, line 590)
LOCATION: /home/kcrafts/public_html/shop/libs/smarty/Smarty.class.php, line 1092, at June 16, 2008, 8:44 pm
Showing backtrace:
trigger_error("Smarty error: [in store_front.tpl line 3]: syntax error: unrecog...", "256") # line 1092, file: /home/kcrafts/public_html/shop/libs/smarty/Smarty.class.php
Smarty.trigger_error("[in store_front.tpl line 3]: syntax error: unrecognized tag 'loa...", "256") # line 1814, file: /home/kcrafts/public_html/shop/libs/smarty/Smarty.class.php
Smarty._trigger_fatal_error("syntax error: unrecognized tag 'load_presentation_object'", "store_front.tpl", "3", "/home/kcrafts/public_html/shop/libs/smarty/Smarty_Compiler.class...", "590", "256") # line 2216, file: /home/kcrafts/public_html/shop/libs/smarty/Smarty_Compiler.class.php
Smarty_Compiler._syntax_error("unrecognized tag 'load_presentation_object'", "256", "/home/kcrafts/public_html/shop/libs/smarty/Smarty_Compiler.class...", "590") # line  590, file: /home/kcrafts/public_html/shop/libs/smarty/Smarty_Compiler.class.php
Smarty_Compiler._compile_tag("load_presentation_object filename="store_front" assign="obj"") # line  312, file: /home/kcrafts/public_html/shop/libs/smarty/Smarty_Compiler.class.php
Smarty_Compiler._compile_file("store_front.tpl", "{* smarty *}
{config_load file="site.conf"}
{load_presentation_o...", null) # line 1488, file: /home/kcrafts/public_html/shop/libs/smarty/Smarty.class.php
Smarty._compile_source("store_front.tpl", "{* smarty *}
{config_load file="site.conf"}
{load_presentation_o...", null, "/home/kcrafts/public_html/shop/presentation/templates_c/%%41^412...") # line 1421, file: /home/kcrafts/public_html/shop/libs/smarty/Smarty.class.php
Smarty._compile_resource("store_front.tpl", "/home/kcrafts/public_html/shop/presentation/templates_c/%%41^412...") # line 1253, file: /home/kcrafts/public_html/shop/libs/smarty/Smarty.class.php
Smarty.fetch("store_front.tpl", null, null, true) # line 1105, file: /home/kcrafts/public_html/shop/libs/smarty/Smarty.class.php
Smarty.display("store_front.tpl") # line   20, file: /home/kcrafts/public_html/shop/index.php
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Mon Jun 16, 2008 6:09 pm    Post subject: Reply with quote

Again a wrong path.

Not /libs/smarty/plugins/function/function.load_presentation_object.php
But /libs/smarty/plugins/function.load_presentation_object.php

Compared to your previous post you changed the plugin name right?
Did you change the function name as well?

function smarty_function_load_presentation_object (....)


Last edited by U.Tews on Mon Jun 16, 2008 6:16 pm; edited 1 time in total
Back to top
View user's profile Send private message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Mon Jun 16, 2008 6:12 pm    Post subject: Reply with quote

Smarty by default will look in the plugins directory for the plugin file. The default plugins directory is located at libs/smarty/plugins. If it's not there then smarty will look in the alternate directory specified in your config.php file.

Your paths seem to be correct, but check what the following code returns:
Code:
dirname(dirname(_FILE_))


You can do this by creating a small script in the same directory as your config.php file.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Mon Jun 16, 2008 6:19 pm    Post subject: Reply with quote

dirname(dirname(_FILE_)) must return the right value because Smarty does find the template files.
Back to top
View user's profile Send private message
robseek
Smarty Rookie


Joined: 17 Mar 2008
Posts: 18

PostPosted: Mon Jun 16, 2008 10:23 pm    Post subject: Reply with quote

As I understand it, the plugin function header in the second edition book is the following:
function smarty_function_load_presentation_object(...)

This means the file that holds this function should be named function.load_presentation_object.php

The template file that makes the plugin available is store_front.tpl

Try the code below within store_front.tpl:

Code:
{load_presentation_object assign="obj"}


After you have done that place the plugin file in both the default plugins and smarty_plugins directories.
Back to top
View user's profile Send private message
carlos_duran
Smarty n00b


Joined: 20 Aug 2008
Posts: 2

PostPosted: Wed Aug 20, 2008 3:22 am    Post subject: Smarty error: unable to read resource: "store_front.tpl Reply with quote

Hi,

I am new to the book and I seem to be having this problem on chapter 3, it appears that here might be something wrong my setup or config.php that reads:

<?php
// SITE ROOT contains the full path to the tshirtshop folder
define('SITE_ROOT', dirname(dirname(__FILE__)));

// Application directories
define('PRESENTATION_DIR', SITE_ROOT . '/presentation/');
define('BUSINESS_DIR', SITE_ROOT . '/business/');

// Settings needed to configure the Smarty template engine
define('SMARTY_DIR', SITE_ROOT . '/libs/smarty/');
define('TEMPLATE_DIR', PRESENTATION_DIR . 'templates');
define('COMPILE_DIR', PRESENTATION_DIR . 'templates_c');
define('CONFIG_DIR', SITE_ROOT . '/include/configs');
?>

Now, the structure of my folders appear to be correct, it looks like this:

C:\tshirtshop>tree
Folder PATH listing
Volume serial number is D402-37C9
C:.
├───images
├───include
│ └───configs
├───libs
│ └───smarty
│ ├───internals
│ └───plugins
├───presentation
│ ├───templates
│ └───templates_c
└───styles

C:\tshirtshop>

I keep getting this error in my browser:

Smarty error: unable to read resource: "store_front.tpl" in C:\tshirtshop\libs\smarty\Smarty.class.php on line 1092

Any ideas would be greatly appreciated.

Thanks,

Carlos
Back to top
View user's profile Send private message Send e-mail
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Aug 20, 2008 1:54 pm    Post subject: Reply with quote

Code:
Smarty error: unable to read resource: "store_front.tpl" in C:\tshirtshop\libs\smarty\Smarty.class.php on line 1092


It can't find the template file. Try this:

Code:
readfile(TEMPLATE_DIR . '/store_front.tpl');


Once you get that working, try your app again.
Back to top
View user's profile Send private message Visit poster's website
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 Previous  1, 2, 3  Next
Page 2 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