How to customize public functions in Symfony and how to call them in templates?
怪我咯2017-05-16 16:46:59
You can write your own service, For example, create a folder name in your bundle. Service Then create a php inside MyClass.php namespace .....BundleService; class MyClass
{
function HelloWord($value)
{
return 'hello'.$value;
}
}
Add in config.yml
parameters:
myclass.class: ..\..Bundle\Service\MyClass
myclass.value: value
services:
myclass:
class: "%myclass.class%"
arguments: [%myclass.value%]
When using it, write it in the controller
$myclass= $this->get('myclass');
echo $myclass->HelloWord("world");
Detailed explanations are available on the official website http://symfony.com/fr/doc/current/book/service_container.html