假设我有一个实体class A{
private int _calls;
private Stopwatch _sw;
public A(){
_calls = 0;
_sw = new StopWatch();
_sw.Start();
}
public void MethodToMeasure(){
//Do stuff
_calls++;
if(sw.ElapsedMilliseconds > 1000){
_sw.Stop();
//Save or print _calls here before it's zeroed
_calls = 0;
_sw.Restart();
}
}
}
:
Car
适用于学说的Class Car {
$private name;
//...
}
文件:
Car.orm.yml
在相应的...\Bundle\CarBundle\Entity\Car:
...
fields:
name:
type: string
length: 100
...
类中,我想访问CarType
文件的length
值:
Car.orm.yml
如何访问 class CarType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('name', TextType::class, array(
'attr' => array('maxlength' => 100),// Access length here!
))
//...
}
}
课程内length
的{{1}}值?
答案 0 :(得分:1)
这可以通过实体元数据访问。
http://symfony.com/doc/current/form/form_dependencies.html#define-your-form-as-a-service
将实体管理器添加为依赖项。
通过完整的班级名称获取课程元数据:
$classMetadata = $em->getClassMetadata('Bundle\CarBundle\Entity\Car')
获取字段定义:
$classMetadata->getFieldMapping('name')['length']