How to create/use custom classes and helper in symfony 1.4?

∥☆過路亽.° 提交于 2019-11-30 15:16:28

As for the custom library part of the question, you might probably want to put your external library into the lib/vendor folder. Since symfony doesn't automatically load everything that's in there, you'll have to tell its autoloader to do so.

You can either extend your config/ProjectConfiguration.class.php (as described here) or (and this is the much simpler and cleaner way) you add them to your config/autoload.yml (you might have to create this one). For the latter option, this is a great place to start looking at.

sumkincpp

It seems to be a duplicate question.

As asked in symfony's 1.2 "Definitive Guide" docs :

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, if you want to create custom helper FooBar for foo() function, create file lib/helper/FooBarHelper.php :

function foo() {echo "foo!"; }

to use it in your template:

use_helper('FooBar')
....

foo(); //outs "foo!"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!