| View previous topic :: View next topic |
| Author |
Message |
ericdeng Smarty Rookie
Joined: 01 Mar 2011 Posts: 9
|
Posted: Tue Mar 01, 2011 2:09 pm Post subject: Smarty3 Error |
|
|
Does the new Smarty3.0.7 support Xampp 1.7.4 ?
This the Error I get from Xampp 1.7.4
| Code: |
ERRNO: 8
TEXT: Undefined index: name
LOCATION: D:\Xampp\htdocs\Smart\presentation\templates_c\
e754709b42dd9925c5a72470cd9beebc6eca5add.file.departments_list.tpl.cache.php, line 61, at March 1, 2011, 1:51 pm
Showing backtrace:
include("D:\Xampp\htdocs\Smart\presentation\templates_c\e754709b42dd9925c...") # line 432, file: D:\Xampp\htdocs\Smart\libs\sysplugins\smarty_internal_template.php
Smarty_Internal_Template.renderTemplate() # line 567, file: D:\Xampp\htdocs\Smart\libs\sysplugins\smarty_internal_template.php
Smarty_Internal_Template.getRenderedTemplate() # line 51, file: D:\Xampp\htdocs\Smart\libs\sysplugins\smarty_internal_template.php(518) : eval()'d code
eval() # line 518, file: D:\Xampp\htdocs\Smart\libs\sysplugins\smarty_internal_template.php
Smarty_Internal_Template.renderTemplate() # line 567, file: D:\Xampp\htdocs\Smart\libs\sysplugins\smarty_internal_template.php
Smarty_Internal_Template.getRenderedTemplate() # line 338, file: D:\Xampp\htdocs\Smart\libs\Smarty.class.php
Smarty.fetch("market_front.tpl", null, null, null, true) # line 382, file: D:\Xampp\htdocs\Smart\libs\Smarty.class.php
Smarty.display("market_front.tpl") # line 16, file: D:\Xampp\htdocs\Smart\index.php
|
The Web Server is running PHP ver 5.3.5 and I made the newest versions of the smarty and PEAR libraries available. With Smarty ver 3.0.7
This defined by a plugin in SMARTY's presentation directory or as a registered function in the application script.
| Code: |
<?php
// Plug-in functions inside plug-in files must be named: smarty_type_name
function smarty_function_load_presentation_object($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);
}
?>
|
This the file for department_list.tpl
| Code: | | {load_presentation_object filename="departments_list" assign="obj"} |
Is there any syntax problem for the new version 3?
How to solve backtrace issue ?
Thanks I am new in smarty3 
Last edited by ericdeng on Tue Mar 01, 2011 4:57 pm; edited 1 time in total |
|
| Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 4177 Location: Hamburg / Germany
|
Posted: Tue Mar 01, 2011 4:25 pm Post subject: |
|
|
| Quote: | Smarty now follows the PHP error_reporting level by default. If PHP does not mask E_NOTICE and you try to access an unset template variable, you will now get an E_NOTICE warning. To revert to the old behavior:
$smarty->error_reporting = E_ALL & ~E_NOTICE; |
It looks like that you try to access in your template an undefined index 'name' of an array variable and E_NOTICE ia enabled. |
|
| Back to top |
|
ericdeng Smarty Rookie
Joined: 01 Mar 2011 Posts: 9
|
Posted: Tue Mar 01, 2011 4:53 pm Post subject: |
|
|
| U.Tews wrote: | | Quote: | Smarty now follows the PHP error_reporting level by default. If PHP does not mask E_NOTICE and you try to access an unset template variable, you will now get an E_NOTICE warning. To revert to the old behavior:
$smarty->error_reporting = E_ALL & ~E_NOTICE; |
It looks like that you try to access in your template an undefined index 'name' of an array variable and E_NOTICE ia enabled. |
Thanks for you reply
This condition I also considered there are several file regarding this
php.ini itself
/include/config.php
| Code: |
define('IS_WARNING_FATAL', true);
define('DEBUGGING', true);
// The error types to be reported
define('ERROR_TYPES', E_ALL & ~E_NOTICE);
// Settings about mailing the error messages to admin
define('SEND_ERROR_MAIL', false);
|
and
/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::__construct();
// 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';
$this->cache_dir = CACHE_DIR;
$this->cache_lifetime = 3600 ;
$this->caching = 1;
$this->error_reporting = E_ALL & ~E_NOTICE;
}
}
?>
|
i try all the case choose one by one
but still get the same error.... : (
can you help me to check the syntax in above about
---> base on smarty3.0.7 with PHP5.3.5
Thanks again ! |
|
| Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 4177 Location: Hamburg / Germany
|
Posted: Tue Mar 01, 2011 5:35 pm Post subject: |
|
|
What code is at
templates_c\
e754709b42dd9925c5a72470cd9beebc6eca5add.file.departments_list.tpl.cache.php, line 61 ? |
|
| Back to top |
|
ericdeng Smarty Rookie
Joined: 01 Mar 2011 Posts: 9
|
Posted: Tue Mar 01, 2011 6:06 pm Post subject: |
|
|
| U.Tews wrote: | What code is at
templates_c\
e754709b42dd9925c5a72470cd9beebc6eca5add.file.departments_list.tpl.cache.php, line 61 ? |
| Code: |
<?php echo $_smarty_tpl->getVariable('obj')->value->mDepartments[$_smarty_tpl->getVariable('smarty')->value['section']['i']['index']]['name'];?>
|
This code from line 58 - 64
| Code: |
<li>
<a <?php echo $_smarty_tpl->getVariable('selected')->value;?>
href="<?php echo $_smarty_tpl->getVariable('obj')->value->mDepartments[$_smarty_tpl->getVariable('smarty')->value['section']['i']['index']]['link_to_department'];?>
">
<?php echo $_smarty_tpl->getVariable('obj')->value->mDepartments[$_smarty_tpl->getVariable('smarty')->value['section']['i']['index']]['name'];?>
</a>
</li>
|
Two more file regrading to line 61
departments_list.php
| Code: |
<?php
// Manages the departments list
class DepartmentsList
{ /* Public variables available in departments_list.tpl Smarty template */
public $mSelectedDepartment = 0;
public $mDepartments;
// Constructor reads query string parameter through the gobal config file call the databasehandler
public function __construct()
{
/* If DepartmentId exists in the query string, we're visiting a department */
if (isset ($_GET['DepartmentId']))
$this->mSelectedDepartment = (int)$_GET['DepartmentId'];
}
/* Calls business tier method to read departments list and create their links */
public function init()
{
// Get the list of departments from the business tier
// From Persentation tier -> Buiness tier
$this->mDepartments = Catalog::GetDepartments();
// Create the department links
for ($i = 0; $i < count($this->mDepartments); $i++)
$this->mDepartments[$i]['link_to_department'] ='index.php?DepartmentId=' . $this->mDepartments[$i]['department_id'];
}
}
?>
|
departments_list.tpl
| Code: |
{load_presentation_object filename="departments_list" assign="obj"}
{* Start departments list *}
<div class="mainsidecontent">
<ul>
{* Loop through the list of departments *}
{section name=i loop=$obj->mDepartments}
{assign var=selected value=""}
{* Verify if the department is selected to decide what CSS style to use *}
{if ($obj->mSelectedDepartment == $obj->mDepartments[i].department_id)}
{assign var=selected value="class=\".mainsidecontent li\""}
{/if}
<li>
{* Generate a link for a new department in the list *}
<a {$selected} href="{$obj->mDepartments[i].link_to_department}">
{$obj->mDepartments[i].name}
</a>
</li>
{/section}
</ul>
</div>
{* End departments list *}
|
This is all : )
which i already return
you have any idea? |
|
| Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 4177 Location: Hamburg / Germany
|
Posted: Tue Mar 01, 2011 6:17 pm Post subject: |
|
|
| {$obj->mDepartments[i].name} is failing because your data seem not to contain the 'name' element |
|
| Back to top |
|
ericdeng Smarty Rookie
Joined: 01 Mar 2011 Posts: 9
|
Posted: Tue Mar 01, 2011 6:21 pm Post subject: |
|
|
| U.Tews wrote: | | {$obj->mDepartments[i].name} is failing because your data seem not to contain the 'name' element |
seem like that
after i change to
{$obj->mDepartments[i].department_id}
1.2.3 is return on with no error : )
but what would i do exactly?
The the name is already saved in mysql
is the problem come from table?
pls tell me how do fix it thanks |
|
| Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7042 Location: Lincoln Nebraska, USA
|
Posted: Tue Mar 01, 2011 6:27 pm Post subject: |
|
|
A) remove {$obj->mDepartments[i].name} from the template, it is accessing non-available data anyways
B) fill the data into the object so the "name" attribute is available to the template
C) if "name" is available but in a different area, correct the template syntax to access the data from the correct area. maybe you just have a syntax error?
D) leave the notice error, but mask it in the PHP error handler. I wouldn't recommend this, as the PHP error handler does have its overhead and this should be unnecessary.
FYI Smarty 3.1 will have some changes to gracefully handle unset variable access. |
|
| Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 4177 Location: Hamburg / Germany
|
Posted: Tue Mar 01, 2011 6:28 pm Post subject: |
|
|
your Catalog::GetDepartments() does not return the 'name' element.
You must fix it there. It's not a problem of Smarty |
|
| Back to top |
|
ericdeng Smarty Rookie
Joined: 01 Mar 2011 Posts: 9
|
Posted: Tue Mar 01, 2011 6:32 pm Post subject: |
|
|
| U.Tews wrote: | your Catalog::GetDepartments() does not return the 'name' element.
You must fix it there. It's not a problem of Smarty |
Got cha
Very appreciated !
I can't wait to see Smarty 3.1  |
|
| Back to top |
|
|