alexandresalome / web-bundle
v0.1.2
2014-01-31 21:24 UTC
Requires
- php: >=5.3.3
- symfony/symfony: ~2.3
This package is auto-updated.
Last update: 2019-06-27 09:23:44 UTC
README
我建议你在代码中挑选片段,但不要实际使用它(非常不稳定)。
安装
将alexandresalome/web-bundle添加到你的composer.json
{ "require": { "alexandresalome/web-bundle": "dev-master" } }
更新你的依赖并添加到你的AppKernel
public function registerBundles() { return array( // ... new Alex\WebBundle\AlexWebBundle() ) }
基础控制器
此包中的Controller
提供了一组有用的方法。
请查看类以获取完整的功能列表。
数据固定
namespace Acme\DemoBundle\DataFixtures\ORM; use Alex\WebBundle\DataFixtures\ORMFixture; use Doctrine\Common\Persistence\ObjectManager; class UserData extends ORMFixture { public function load(ObjectManager $manager) { // access a container service $this->get('security.encoder_factory'); } }
表单模板
此包中提供了Twitter Bootstrap 3.0表单模板。在Twig配置中,添加表单模板
twig: form: resources: [ "AlexWebBundle::form_bootstrap3_layout.html.twig" ]
地区监听器
如果你想允许用户在给定集中选择地区,你可以在config.yml
文件中打开地区监听器
alex_web: locale_listener: [ fr_FR, en_US, pt_PT ]
此配置将用户地区限制为以下之一。默认行为是在会话中存储此地区。如果你不想使用会话但仍然想使用监听器
alex_web: locale_listener: enabled: true locales: [fr_FR, en_US] session_key: null # disable persistence in session
Twig扩展
|format_interval
示例
Duration: {{ job.finishedAt.diff(jobStartedAt) }} {# should be job.duration #}
此方法将将DateInterval对象转换为字符串表示。
分页模板
如果你使用我的分页库,你可能喜欢使用模板AlexWebBundle::pagination.html.twig
。要使用它
{% embed "AlexWebBundle::pagination.html.twig" %} {% block colspan '3' %} {% block head %} <th>Username</th> <th>Fullname</th> <th>Actions</th> {% endblock %} {% block body %} {% for user in pager %} <tr> {# ... #} </tr> {% else %} <tr><td colspan="{{ block('colspan') }}"><em>no user</em></td></tr> {% endfor %} {% endblock %} {% endembed %}
表单额外小部件
表单部分
使用部分结构化你的表单。部分将字段分组,并在上方有标题,这样你的表单就更有结构了
$builder ->add($builder->create('informations' 'form_section') ->add('firstname', 'text') ->add('lastname', 'text') ) ->add($builder->create('contacts', 'form_section') ->add('main', 'contact') )
表单选项卡
这是一个带有选项卡的表单示例
$builder = $this->get('form.factory')->createBuilder('form_tabs'); $builder ->add($builder->create('informations', 'form_tab') ->add('firstname', 'text') ->add('lastname', 'text') ) ->add($builder->create('contacts', 'form_tab') ->add('main', 'contact') ) ;