如何使用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
我有以下代码:
$getmoney = Doctrine::getTable('Countries')->find(1);
$insertmoney = new Accounts();
$insertmoney->userid = $userid;
$insertmoney[$getmoney->getCurrency()] = $getmoney->getBaby();
$insertmoney->save();
Run Code Online (Sandbox Code Playgroud)
并且Doctrine生成的查询是:
INSERT INTO accounts (1, userid, 2) VALUES ('0', '31', '15')
Run Code Online (Sandbox Code Playgroud)
但它似乎有一个SQL错误: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1, userid, 2) VALUES ('0', '31', '15')' at line 1
相关性查询将是:
INSERT INTO accounts (`1`, `userid`, `2`) VALUES ('0', '31', '15')
Run Code Online (Sandbox Code Playgroud)
可能错误的是列数字的不幸名称.我只是因为它使事情用数字很多容易.
如何生成在" ` " …
我有一个过滤器,查询数据库以检查用户名是否与密码匹配.如果返回false,则筛选器将重定向到"logout"操作.唯一的问题是它将进入无限循环,因为过滤器也适用于"注销"操作.
有什么方法可以"关闭"该操作的过滤器吗?
我需要在模型之后生成的表单中使用sfValidatorDoctrineChoice的提交值.
我试过$this->getValue('country')但它不起作用:
$query2 = Doctrine_Core::getTable('sate')->createQuery('s')
->select('s.id')
->where('s.idcountry = ?', $this->getValue('country'));
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得该参数?
如何在不覆盖已生成的类的情况下向Database表中添加列?(学说)我需要编辑哪些文件?
如果我只是在数据库中添加列,我就不能使用Doctrine ORM的set和get函数.
小部件看起来像这样:
$this->widgetSchema['tara'] = new sfWidgetFormChoice(array(
'choices' => Doctrine_Core::getTable('Users')->getCountry(),
'expanded' => false,
'multiple' => false,
));
Run Code Online (Sandbox Code Playgroud)
和getCountry函数:
static public $country = array(
'1' => 'România',
'2' => 'United States',
'3' => 'France',
);
public function getCountry()
{
return self::$country;
}
Run Code Online (Sandbox Code Playgroud)
现在小部件呈现如下:
但我希望它看起来像这样:
我怎样才能做到这一点?
symfony-1.4 ×5
symfony1 ×5
php ×4
doctrine ×3
doctrine-1.2 ×1
filter ×1
forms ×1
select ×1
sql ×1
symfony ×1