Question about referencing smarty in the php class ??? Problem Overview: If you want to call the smarty method in the class, the following error occurs: PHPFatalerror: Using $ thiswhennotinobjectcontextinG: \ SVN \ YCMS \ localhost \ core \ smarty \ sysplugins \ sma php class reference smarty question ???
Problem Overview:
If you want to call the smarty method in the class, the following error occurs:
PHP Fatal error: Using $ this when not in object context in G: \ SVN \ YCMS \ localhost \ core \ smarty \ sysplugins \ smarty_internal_data.php on line 38
I hope you can help me with the following code: [app/model/home. php has introduced the _ Model class through other pages]:
App/model/home. php
PHP code
Core/model/index. php
PHP code
Core/config/smarty
PHP code
Template_dir = Y_APP.DS. 'View'; // set the template directory $ smarty-> compile_dir = Y_CACHE.DS. "view_c"; // Set the compilation directory $ smarty-> config_dir = Y_APP.DS. 'config '. DS. 'smarty '; // Configure the directory variable // $ smarty-> php_handling = SMARTY_PHP_ALLOW; // do not approve of setting it to SMARTY_PHP_ALLOW $ smarty-> left_delimiter = "{"; $ smarty-> right_delimiter = "}"; // compile # $ smarty-> compile_check = false; // compile the check variable // Cache $ smarty-> caching = true; // cache template output $ smarty-> cache_dir = Y_CACHE ;// Directory name for storing the template cache # $ smarty-> cache_lifetime = 1; // cache lifecycle?>
There is no problem with File association, and some are not displayed here.
The error message points to the smarty source code, which is also posted here:
PHP code
public function assign($tpl_var, $value = null, $nocache = false) { if (is_array($tpl_var)) { foreach ($tpl_var as $_key => $_val) { if ($_key != '') { $this->tpl_vars[$_key] = new Smarty_variable($_val, $nocache); } } } else { if ($tpl_var != '') { $this->tpl_vars[$tpl_var] = new Smarty_variable($value, $nocache); } } }
Please kindly advise!
------ Solution --------------------
The assign must be instantiated before it can be referenced. in your class home, the parent class parent: assign () is not instantiated.