Yii多个关系和形式
我已经准备好桌子了Yii多个关系和形式,yii,Yii,我已经准备好桌子了 // Post model return array( 'categories' => array(self::MANY_MANY, 'Category', 'categories_posts(post_id, category_id)') ); 我遇到的问题是,创建此表单时出错: posts id, title, content categories id, name categories_posts post_id, category_i 我很困惑。
// Post model
return array(
'categories' => array(self::MANY_MANY, 'Category', 'categories_posts(post_id, category_id)')
);
我遇到的问题是,创建此表单时出错:
posts
id, title, content
categories
id, name
categories_posts
post_id, category_i
我很困惑。我该怎么做才能纠正这一点呢?我真的认为Yii的AR中有类似Kohana或蛋糕的东西。我想我必须手动添加它们
Property "Post.category_id" is not defined.
我真的认为Yii的AR里有一些像Kohana或蛋糕之类的东西。我想我必须手动添加它们
Property "Post.category_id" is not defined.
我使用Cadvan行为使这更容易。如果像这样的东西最终进入Yii核心,我也不会感到惊讶: 它允许您在控制器中编写如下代码:
foreach ($_POST['category_id'] as $category_id)
{
$categoryPost = new CategoryPost;
$categoryPost->category_id = $category_id;
$categoryPost->post_id = $model->id;
$categoryPost->save();
}
我将其用于更像Buggy而不是我想要的关系小部件/扩展。我不确定,您可能需要使用它来正确构造POST变量。我使用CADVANCEDA行为来简化这一过程。如果像这样的东西最终进入Yii核心,我也不会感到惊讶: 它允许您在控制器中编写如下代码:
foreach ($_POST['category_id'] as $category_id)
{
$categoryPost = new CategoryPost;
$categoryPost->category_id = $category_id;
$categoryPost->post_id = $model->id;
$categoryPost->save();
}
我将其用于更像Buggy而不是我想要的关系小部件/扩展。我不确定,您可能需要使用它来正确构造POST变量。以这种方式使用:
内部控制器
为类别创建对象:$modelCat=新类别;
然后在
以这种方式使用:
内部控制器
为类别创建对象:$modelCat=新类别;
然后在
那么,您是否只是使用了CHtml::dropDownList而不是activeDropDownList?然后把这个^^^放在控制器里?我现在有一个类似的问题…:/那么,您是否只是使用了CHtml::dropDownList而不是activeDropDownList?然后把这个^^^放在控制器里?我现在有一个类似的问题…:/
<?php echo CHtml::activeDropDownList(**$modelCat**,'category_id', CHtml::listData(Category::model()->findAll(), 'id', 'name')); ?>