嗨,我正在尝试创建像这里一样的自定义字段,但在添加到service.yml
services:
griffin.type.datetime_to_string:
class: griffin\CoreBundle\Form\DateTimeType
arguments: ["@doctrine.orm.entity_manager"]
tags:
- { name: form.type, alias: datetime_to_string }
我得到Catchable Fatal Error: Argument 1 passed to griffin\CoreBundle\Form\DataTransformer\DateTimeToStringTransformer::__construct() must implement interface Doctrine\Common\Persistence\ObjectManager, null given
任何人有这个问题?
编辑
namespace griffin\CoreBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use griffin\CoreBundle\Form\DataTransformer\DateTimeToStringTransformer;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
/**
* Description of DateTimeType
*
* @author skowron-line
*/
class DateTimeType extends AbstractType {
private $om;
public function __construnct(ObjectManager $om) {
$this->om = $om;
}
public function buildForm(FormBuilderInterface $builder, array $options) {
var_dump($this->om);
$transformer = new DateTimeToStringTransformer($this->om);
$builder->addModelTransformer($transformer);
}
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'invalid_message' => 'err',
));
}
public function getParent() {
return 'text';
}
public function getName() {
return 'datetime_to_string';
}
}
在我的控制器中
$form = $this->createForm(new KlientType(), $klient);