Have problem template variable inside {php}...{/php} - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Have problem template variable inside {php}...{/php} (/showthread.php?tid=60750) |
Have problem template variable inside {php}...{/php} - El Forum - 06-19-2014 [eluser]Unknown[/eluser] Hello every one, hope all of you passing nice days. I need a small help. I am very new in smapty. I am using smarty with codeigniter first time. Now i have a problem to find the difference between two date. Join date and resign comes from a for loop. I attach my code block here. ---------------------------------------------------------------------------------- {foreach $data.exp_info as $exp} {assign var="ex_join_year" value="{$exp->ex_join_year}"} {assign var="ex_resign_year" value="{$exp->ex_resign_year}"} {assign var="ex_join_month" value="{$exp->ex_join_month}"} {assign var="ex_resign_month" value="{$exp->ex_resign_month}"} {php} $date1 = $smarty->get_template_vars('ex_join_year'); $date2 = $smarty->get_template_vars('ex_resign_year'); //$date1 = "2007-Jan"; sample date //$date2 = "2007-feb"; sample date $diff = abs(strtotime($date2) - strtotime($date1)); $years = floor($diff / (365*60*60*24)); $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); printf("%d years, %d months\n", $years, $months); {/php} {/foreach} --------------------------------------------------------------------------------- ex_join_year, ex_resign_year, ex_join_month, ex_resign_month they are smarty template variable, so i cant use them directly under {php}.......{/php}. But i need some run time process using those variables to calculate difference between two days. it shows error when i assign those template variables inside {php}......{/php} it generates these errors A PHP Error was encountered Severity: Notice Message: Undefined variable: smarty Filename: plugins/block.php.php(23) : eval()'d code Line Number: 3 Fatal error: Call to a member function get_template_vars() on a non-object in C:\wamp\www\hms\application\libraries\smarty\libs\plugins\block.php.php(23) : eval()'d code on line 3 Thanks every one |