开发者

How to implement a helper in Symfony 1.4?

开发者 https://www.devze.com 2022-12-18 02:25 出处:网络
I\'d like to create my own helper but can\'t find any help on Google for Symfony 1.4/Doctrine. I guess it has something to do with creating a myClassHelper.clas开发者_StackOverflow中文版s.php in lib/

I'd like to create my own helper but can't find any help on Google for Symfony 1.4/Doctrine.

I guess it has something to do with creating a myClassHelper.clas开发者_StackOverflow中文版s.php in lib/helpers/ or something, but I don't know what to implement, or if specific methods have to be overridden.

Any help would be appreciated!


I don't think that anything changed regarding the helpers in 1.4. From the documentation(although 1.2):

Helper functions (regular PHP functions returning HTML code) should be saved in a file called FooBarHelper.php, where FooBar is the name of the helper group. Store the file in the apps/myapp/lib/helper/ directory (or in any helper/ directory created under one of the lib/ folders of your project) so it can be found automatically by the use_helper('FooBar') helper for inclusion.

So you just put normal functions in a normal file (has nothing to do with classes or methods). The functions can take arbitrary parameters (you decide what they need to create the HTML) and the have to return HTML.

E.g.

MyHelper.php

function hello_word() {
   return '<strong>Hello world!</strong>';
}

and in the template:

<?php use_helper('My') ?>

<!-- somewhere in the template -->
<?php echo hello_world() ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号