How to customize public functions in symfony and call them in templates?
迷茫
迷茫 2017-05-16 16:44:59
0
1
467

How to customize public functions in Symfony and how to call them in templates?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
刘奇

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template