Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

assign bug

 
Post new topic   Reply to topic    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
infira
Smarty n00b


Joined: 28 Oct 2011
Posts: 2

PostPosted: Fri Oct 28, 2011 4:55 pm    Post subject: assign bug Reply with quote

is i assign a obejct to smarty and call object method, and in the method is called assign, the assigned variable dot apply to tempalte file
Code:

<?php
class myObject
{

   public $Smarty = false;


   
   public function __construct(&$Smarty)
   {
      $this->Smarty = &$Smarty;
   }


   public function test($name)
   {
      $this->Smarty->assign($name, "some value");
   }
}


require_once 'smarty/Smarty.class.php';
$Smarty = new Smarty();
$Smarty->compile_check = false;
$Smarty->caching = 0;
$Smarty->force_compile = true;
$Smarty->error_reporting = E_ALL;
$Smarty->plugins_dir = 'smarty/';

$Smarty->template_dir = 'templates/';
$Smarty->compile_dir = 'smarty_compiled_source/';
$Smarty->cache_dir = 'smarty_cache/';

$myObject = new myObject($Smarty);
$Smarty->assignByRef("myObject", $myObject);
$Smarty->display("a.tpl");
?>

a.tpl template file

Code:

{$myObject->test("myNewAssignMent")}

{$myNewAssignMent}



Comes with a error, Undefined index: myNewAssignMent
It use to work in version 3.0.x, but not any more in 3.1.4

How can i fix this proble,
Register obejct is not a option
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sun Oct 30, 2011 2:38 pm    Post subject: Reply with quote

your object should assign the variables to the template object. Smarty 3.1 does have speed optimizations that varibales of the Smarty object are merged into the local scope of the template when the template is called. variables assigned during template rendering to the Smarty object will not be seen.

Code:

// create template object
$template = $smarty->createTempleate('a.tpl');
$myObject = new myObject($template);
$Smarty->assignByRef("myObject", $myObject);
$template->display();


The other option is that your object does return the value and you assign it in the template

Code:
{$myNewAssignMent = $myObject->test(....)}

{$myNewAssignMent}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
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