我的项目是为了多语言,我很远没有完成,但到目前为止,我所有的树枝模板都使用了trans过滤器。构建表单时,哪里是设置标签值的最佳位置?
现在当构建表单时,我希望我的标签也能被翻译,到目前为止,这里是几个formbuilder类之一,问题是:我应该在这里还是在树枝模板内设置标签的值,以便我可以再次使用小枝“反式”过滤器?
<?php
namespace MG\AdminBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class CustomersHomesType extends AbstractType
{
private $customersId = null;
public function __construct($customersId){
$this->customersId = $customersId;
;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('customers_id', 'hidden', array('data'=>$this->customersId,'required'=>true))
->add('name', 'text', array('label'=>'Name:','required'=>true))
->add('streetAddress1', 'text', array('label'=>'Street Address:','required'=>true))
->add('streetAddress2', 'text', array('label'=>'Street Address:','required'=>false))
->add('city', 'text', array('label'=>'City:','required'=>true))
->add('state', 'text', array('label'=>'State:','required'=>true))
->add('zipcode', 'text', array('label'=>'Zip Code:','required'=>true))
->add('type', 'choice', array(
'expanded'=>false,
'label'=>'Address Type:',
'choices' => array('billing' => 'Billing Address ', 'work' => 'Work Address ', 'shipping'=>'Shipping Address '),
'required' => true,
))
->add('subdivision', 'text', array('label'=>'Subdivision:','required'=>false))
->add('directions', 'textarea', array('label'=>'Directions Or Comments:','required'=>false))
->add('phone', 'text', array('label'=>'Phone #1:','required'=>false))
->add('phone2', 'text', array('label'=>'Phone #2:','required'=>false))
->add('save', 'submit', array('label'=>'Save'))
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'MG\AdminBundle\Entity\CustomersHomes'
));
}
/**
* @return string
*/
public function getName()
{
return 'mg_adminbundle_customershomes';
}
}
我非常感激你的时间,我发现通过提问我学得更快,我还保留一个很好的参考来回到这里在stackoverflow。再次,谢谢你。 – MikeGA
没问题,很乐意帮忙。正如我在另一个答案中提到的那样。寻找Symfony所能提供的东西的好地方是Sylius Bundle(https://github.com/Sylius/Sylius)以及FOSUserBundle(https:// github.com/FriendsOfSymfony/FOSUserBundle)。 Symfony CMF包也可能是一个很好的来源,但据我所知它利用了我没有投入任何时间的PHPCR,所以我几乎远离它,这意味着我不能证明它是在学习美德。 – qooplmao