如何使用Symfony 2中的数据库表创建包含值的选择列表?
我有2个实体:Student和Classroom,具有ManyToOne关系,我需要创建一个包含以下字段的表单:姓名,姓氏,年龄,教室(从可用班级中选择列表).
在我的学生表格中我有
$builder
->add('name')
->add('surname')
->add('age')
->add('classroom', new ClassroomType())
;
Run Code Online (Sandbox Code Playgroud)
在我的课堂表格中我有这个:
$classrooms =$this->getDoctrine()->getRepository('UdoCatalogBundle:Classroom')->findAll();
$builder
->add('clasa','choice',array('choices' => array($classrooms->getId() => $classrooms->getName())));
Run Code Online (Sandbox Code Playgroud)
我得到以下错误:
Fatal error: Call to undefined method Udo\CatalogBundle\Form\ClassroomType::getDoctrine() in /var/www/html/pos/src/Udo/CatalogBundle/Form/ClassroomType.php on line 13
Run Code Online (Sandbox Code Playgroud)
亲切的问候,Cearnau Dan
我正在使用Symfony 2和Doctrine 2为iOS应用程序创建Web服务(JSON).
要获取我的实体我做:
$articles = $this->getDoctrine()->getRepository('UdoPaddujourBundle:MenuArticle')->findAll();
Run Code Online (Sandbox Code Playgroud)
我必须告诉你:
$article = array();
$article = $articles->toArray();
Run Code Online (Sandbox Code Playgroud)
给我以下错误:
Fatal error: Call to a member function toArray() on a non-object
Run Code Online (Sandbox Code Playgroud)
同样的事情发生了
$article = $articles->exportTo('json');
Run Code Online (Sandbox Code Playgroud)
我怎样才能创建一个json响应?
亲切的问候,Cearnau Dan
编辑:var_dump($ articles)=
array(18) {
[0]=>
object(Udo\PaddujourBundle\Entity\MenuArticle)#50 (4) {
["id":"Udo\PaddujourBundle\Entity\MenuArticle":private]=>
int(1)
["name":"Udo\PaddujourBundle\Entity\MenuArticle":private]=>
string(17) "My Article Name 1"
["description":"Udo\PaddujourBundle\Entity\MenuArticle":private]=>
string(26) "My Article Description 1"
["price":"Udo\PaddujourBundle\Entity\MenuArticle":private]=>
float(20)
}
[1]=> ...
Run Code Online (Sandbox Code Playgroud)
我怎样才能遍历所有"属性名称"?这就是我所拥有的:
$myarray=array();
$myArray["name"]=array();
$myArray["description"]=array();
foreach($articles in $article)
{
array_push($myArray["name"], $article->getName());
array_push($myArray["description"], $article->getDescription());
}
Run Code Online (Sandbox Code Playgroud) 我目前在模态视图和弹出窗口方面遇到了一些麻烦.这可能是同样的问题,但我不确定.
我对模态视图的问题是我无法更改动画或过渡样式.例如,我写
self.modalPresentationStyle = UIModalPresentationPageSheet;
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:IpModal animated:YES];
Run Code Online (Sandbox Code Playgroud)
但是模态视图仍然以其原始过渡样式显示为全屏.
此外,我与弹出窗口的问题是非常相似的.即使我使用"NO"作为参数调用dismissPopover:animated:方法,转换仍然是动画的.
提前致谢.