How do we call a php function in the template page in symfony 1.4 doctrine. Suppose i want to call a function add() in the template page where should i define the function add()? Will i do it in the actions page? Can we define tht function in actions page?
Waiting fr a quick reply
You can use helper. For example:
apps/yourapp/lib/helper/myNewHelper.php
<?php
if (!function_exists("yourfunc"))
{
function yourfunc($variable){
// Your code here
}
return $variable;
}
}
?>
And in themplate, for example
apps/yourapp/modules/yourmodule/templates/indexSuccess.php
<?php use_helper('myNew'); ?>
<?php echo yourfunc($data->getSomeData()) ?>
You shouldn't do actions inside a template. For that you should separate your code in small components
. In your cicle (foreach in this case, maybe while in yours):
<?php foreach($array => $param): ?>
<?php include_component('module', 'action', array('param' => $param));
<?php endforeach ?>
And then, in your components.class.php
you execute your timetable($param);
function, displaying the result in a partial.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.