Note that there are some explanatory texts on larger screens.

plurals
  1. POYii Many_Many Relationship and Form
    text
    copied!<pre><code>// Post model return array( 'categories' =&gt; array(self::MANY_MANY, 'Category', 'categories_posts(post_id, category_id)') ); </code></pre> <p>I already have the setup of tables</p> <pre><code>posts id, title, content categories id, name categories_posts post_id, category_i </code></pre> <p>The problem I have is that I am getting an error when creating this form:</p> <pre><code>&lt;?php $form=$this-&gt;beginWidget('CActiveForm', array( 'id'=&gt;'post-form', 'enableAjaxValidation'=&gt;false, )); ?&gt; &lt;p class="note"&gt;Fields with &lt;span class="required"&gt;*&lt;/span&gt; are required.&lt;/p&gt; &lt;?php echo $form-&gt;errorSummary($model); ?&gt; &lt;div class="row"&gt; &lt;?php echo $form-&gt;labelEx($model,'title'); ?&gt; &lt;?php echo $form-&gt;textField($model,'title',array('size'=&gt;60,'maxlength'=&gt;255)); ?&gt; &lt;?php echo $form-&gt;error($model,'title'); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;?php echo $form-&gt;labelEx($model,'uri'); ?&gt; &lt;?php echo $form-&gt;textField($model,'uri',array('size'=&gt;60,'maxlength'=&gt;255)); ?&gt; &lt;?php echo $form-&gt;error($model,'uri'); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;?php echo $form-&gt;labelEx($model,'content'); ?&gt; &lt;?php echo $form-&gt;textArea($model,'content',array('rows'=&gt;6, 'cols'=&gt;50)); ?&gt; &lt;?php echo $form-&gt;error($model,'content'); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;?php // echo $form-&gt;labelEx($model,'content'); ?&gt; &lt;?php echo CHtml::activeDropDownList($model,'category_id', CHtml::listData(Category::model()-&gt;findAll(), 'id', 'name')); ?&gt; &lt;?php // echo $form-&gt;error($model,'content'); ?&gt; &lt;/div&gt; &lt;div class="row buttons"&gt; &lt;?php echo CHtml::submitButton($model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt; &lt;/div&gt; &lt;?php $this-&gt;endWidget(); ?&gt; </code></pre> <p>The error is:</p> <pre><code>Property "Post.category_id" is not defined. </code></pre> <p>I am quite confused. What should I be doing to correct this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload