|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
dssouto Smarty n00b
Joined: 22 Jan 2018 Posts: 3
|
Posted: Mon Jan 22, 2018 11:36 pm Post subject: Problem with Smart and on_start(); ob_get_contents( |
|
|
Please whom can you evaluate thank you:
I'm trying to run one recursive call to the code below.
function createTR($error_handler, $input_name, $ld_text, $input_val, $colspan = 1, $input_size = 35,$red=FALSE){
ob_start();
$this->smarty->assign('must','');
if ($error_handler || $red) {
$sBuffer="<font color=\"$this->error_fontcolor\">* $ld_text</font>";
$this->smarty->assign('must',1);
}
else $sBuffer=$ld_text;
$this->smarty->assign('must',1);
$this->smarty->assign('sItem',$sBuffer);
$this->smarty->assign('sColSpan1',"colspan=1");
$this->smarty->assign('sColSpan2',"colspan=$colspan");
$this->smarty->assign('sFormWidth','width="auto"');
$this->smarty->assign('sInput','<input name="'.$input_name.'" type="text" size="'.$input_size.'" value="'.$input_val.'" >');
$this->smarty->display('registration_admission/reg_row.tpl');
$this->smarty->assign('sBarcodeImg','');
//echo '<br>'.$sBuffer;
$sBuffer = ob_get_contents();
ob_end_clean();
//$this->toggle=!$this->toggle;
return $sBuffer;
}
The first time works perfect, but from the second and on call The Buffer remains with the fist content. I debugged the code and noticed that ob_get_contents () always brings the contents of the first call, may be the ob_end_clean() is not running.
Someone has had a case that looks like it might help.
Thank you. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Jan 23, 2018 12:53 pm Post subject: |
|
|
There's multiple issues with your code, but two most glaring and most relevant is that you're
1. Using output buffering and Smarty::display() where you should have used just Smarty::fetch().
2. You're caching the output without a defined cache key. Either turn off caching or supply the proper caching key.
The less glaring issues are:
3. Presentation logic in PHP code ("if ($error_handler || $red) {", "assign('sInput', …");
4. ->assign('must', 1) always defined, exalting the p.3. |
|
Back to top |
|
dssouto Smarty n00b
Joined: 22 Jan 2018 Posts: 3
|
Posted: Wed Jan 24, 2018 2:29 am Post subject: |
|
|
Please what version is present fetch()? i changed for the code for this
$smarty->caching = true;
if(!$smarty->is_cached("registration_admission/reg_row.tpl")){
$this->smarty->assign('must','');
if ($error_handler || $red) {
$sBuffer="<font color=\"$this->error_fontcolor\">* $ld_text</font>";
$this->smarty->assign('must',1);
}
else $sBuffer=$ld_text;
$this->smarty->assign('must',1);
$this->smarty->assign('sItem',$sBuffer);
$this->smarty->assign('sColSpan1',"colspan=1");
$this->smarty->assign('sColSpan2',"colspan=$colspan");
$this->smarty->assign('sFormWidth','width="auto"');
$this->smarty->assign('sInput','<input name="'.$input_name.'" type="text" size="'.$input_size.'" value="'.$input_val.'" >');
$sBuffer = $smarty->fetch("registration_admission/reg_row.tpl");
//$sBuffer = $smarty->display("registration_admission/reg_row.tpl");
$this->smarty->assign('sBarcodeImg','');
$smarty->caching = false;
}
return $sBuffer;
but i have error Call to undefined method stdClass::is_cached() and the smae fot all displayi() or fetch() |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Jan 25, 2018 2:25 pm Post subject: |
|
|
dssouto wrote: | Please what version is present fetch()? |
All supported versions.
Quote: | i changed for the code for this
Code: | $smarty->caching = true;
if(!$smarty->is_cached("registration_admission/reg_row.tpl")){
$this->smarty->assign('must','');
if ($error_handler || $red) {
$sBuffer="<font color=\"$this->error_fontcolor\">* $ld_text</font>";
$this->smarty->assign('must',1);
}
else $sBuffer=$ld_text;
$this->smarty->assign('must',1);
$this->smarty->assign('sItem',$sBuffer);
$this->smarty->assign('sColSpan1',"colspan=1");
$this->smarty->assign('sColSpan2',"colspan=$colspan");
$this->smarty->assign('sFormWidth','width="auto"');
$this->smarty->assign('sInput','<input name="'.$input_name.'" type="text" size="'.$input_size.'" value="'.$input_val.'" >');
$sBuffer = $smarty->fetch("registration_admission/reg_row.tpl");
//$sBuffer = $smarty->display("registration_admission/reg_row.tpl");
$this->smarty->assign('sBarcodeImg','');
$smarty->caching = false;
}
return $sBuffer; |
but i have error Call to undefined method stdClass::is_cached() and the smae fot all displayi() or fetch() |
Choose one: either "$this->smarty" or "$smarty".
And the way you changed it, is just meaningless. |
|
Back to top |
|
dssouto Smarty n00b
Joined: 22 Jan 2018 Posts: 3
|
Posted: Sat Jan 27, 2018 10:45 am Post subject: |
|
|
Hello, to run I had to change the code and take out the calls Smarty -
I changed the code for this version.
ob_start();
$sBuffer= '<tr>'
if ($error_handler || $red) {
$sBuffer .= '<td class="input_item_must" collspan=1><font color="'.$this->error_fontcolor.'">*'.$ld_text.'</font></td>';
$sBuffer .= '<td class="reg_input_must" collspan=1><input name="'.$input_name.'" type="text" size="'.$input_size.'" value="'.$input_val.'"'>';
}
else {
$sBuffer .= '<td class="reg_item" collspan=1>'.$ld_text.'</td>;
$sBuffer .= '<td class="reg_input" collspan=1><input name="'.$input_name.'" type="text" size="'.$input_size.'" value="'.$input_val.'"' >
}
$sBuffer .= '</tr>';
echo $sBuffer;
$sBuffer = ob_get_contents();
ob_end_clean();
return $sBuffer;
I would very much like to see the reason for this problem.
The previous Code and template are these
ob_start ();
$ this-> smarty-> assign ('must', '');
if ($ error_handler || $ red) {
$ sBuffer = "<font color = \" $ this-> error_fontcolor \ "> * $ ld_text </ font>";
$ this-> smarty-> assign ('must', 1);
}
else $ sBuffer = $ ld_text;
$ this-> smarty-> assign ('must', 1);
$ this-> smarty-> assign ('sItem', $ sBuffer);
$ this-> smarty-> assign ('sColSpan1', 'colspan = 1');
$ this-> smarty-> assign ('sColSpan2', 'colspan = $ colspan');
$ this-> smarty-> assign ('sFormWidth', 'width = "auto"');
$ this-> smarty-> assign ('sInput', '<input name = "' $ input_name. '" type = "text" size = "' $ input_size. "> ');
$ this-> smarty-> display ('registration_admission / reg_row.tpl');
$ this-> smarty-> assign ('sBarcodeImg', '');
// echo '<br>'. $ sBuffer;
$ sBuffer = ob_get_contents ();
ob_end_clean ();
// $ this-> toggle =! $ this-> toggle;
return $ sBuffer;
<tr>
<td {{if {must}} {{$ sColSpan1}}> {{$ sItem}} </ td>
<td {{if {must}} {{$ sInput}} {{$ sInput}} {{$ sInput}} </ td>
</ tr>
thank you |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Jan 27, 2018 12:06 pm Post subject: |
|
|
I've explained the problem in very first post, but you don't want to read it.
Code: | $smarty->assign( all your vars from a given dataset );
return $smarty->fetch( your template, some dataset-unique identificator as a cache_id ); |
|
|
Back to top |
|
|
|
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
|
|