تالار گفتمان nCIS.ir

نسخه‌ی کامل: model attributes not set
شما در حال مشاهده نسخه آرشیو هستید. برای مشاهده نسخه کامل کلیک کنید.
سلام
در این کد مقدار با پست ارسال میشه ولی
کد:
$model->attributes
مقدار نمی گیره چرا ؟

 public function actionCreate()
{
$this->pageTitle = ' ایجاد مطلب' ;
$model=new Content;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['Content']))
{
$model->attributes=$_POST['Content'];

if($model->save())
$this->redirect(array('view','id'=>$model->id));
}

$this->render('create',array(
'model'=>$model,
));
}



اکشن فرم
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'content-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>
<div class="panel panel-primary">
<div class="panel-heading ">
<?php
$header = ($model->isNewRecord)?  'ایجاد مطلب' :   'ویرایش مطلب';
echo $header ; 
?>
</div>
<div class="panel-body">
   <?php 
  echo CHtml::submitButton('ذخیره و بستن',array('class'=>'btn btn-success button')).'&nbsp;';
  echo CHtml::link('انصراف',array('content/admin'), array('class'=>'btn btn-danger ','name'=>'cancel'));
   ?>
</div>
</div>
<ul class="nav nav-tabs">
 <li class="active"><a data-toggle="tab" href="#home">مطلب</a></li>
 <li><a data-toggle="tab" href="#publish">گزینه های انتشار</a></li>
 <li><a data-toggle="tab" href="#meta">گرینه های متا</a></li>
</ul>

<?php echo $form->errorSummary($model, null, null, array('class'=>'alert alert-danger')); ?>
<div class="tab-content">
 <div id="home" class="tab-pane fade in active">
  <br/>
   <div class="col-md-12">
<div class="col-md-6 form-inline">
<?php echo $form->labelEx($model,'title'); ?>
<?php echo $form->textField($model,'title',array('class'=>'form-control input-xs bg-color','size'=>50,'maxlength'=>50)); ?>
</div>

<div class="col-md-6 form-inline">
<?php echo $form->labelEx($model,'alias'); ?>
<?php echo $form->textField($model,'alias',array('class'=>'form-control input-xs bg-color','size'=>50,'maxlength'=>50)); ?>
</div>
  </div>
  <div class="col-md-12">
  <br/>
  <div class="col-md-8">
<?php echo $form->labelEx($model,'fulltext'); ?>
<?php 
$this->widget('application.extensions.tinymce.SladekTinyMce');
echo $form->textArea($model,'fulltext',array('id'=>'fulltext','rows'=>6, 'cols'=>50)); ?>
  <script type="text/javascript">
   tinymce.init({
   selector: "textarea#fulltext",
   theme: "modern",
   height : 200 ,
   plugins: [
         "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
         "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
         "save table contextmenu directionality emoticons template paste textcolor"
   ],
  content_css: "css/content.css",
  toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons", 
  style_formats: [
        {title: 'Bold text', inline: 'b'},
        {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
        {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
        {title: 'Example 1', inline: 'span', classes: 'example1'},
        {title: 'Example 2', inline: 'span', classes: 'example2'},
        {title: 'Table styles'},
        {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
    ]
}); 
</script>
  </div>
  <div class="col-md-4">
  <div class="col-md-12">
<?php echo $form->labelEx($model,'category_id',array('style'=>'margin-left:5px;')); ?>
<?php echo $form->dropDownList($model,'category_id',array(1=>'aed'),array('value'=>$model->category_id,'class'=>'selectpicker','style'=>'width:200px;')); ?>
</div>
<div class="col-md-12">
<?php echo $form->labelEx($model,'featured',array('style'=>'padding-top:10px;margin-left:25px;')); ?>
<?php echo $form->dropDownList($model,'featured',array(0=>'خیر',
1=>'بلی'),array('value'=>$model->featured,'class'=>'selectpicker','data-style'=>'btn-success','style'=>'width:200px;')); ?>
</div>
<div class="col-md-12">
<?php echo $form->labelEx($model,'confirmed',array('style'=>'padding-top:10px;margin-left:21px;')); ?>
<?php echo $form->dropDownList($model,'confirmed',array(0=>'خیر',
1=>'بلی'),array('value'=>$model->confirmed,'class'=>'selectpicker','style'=>'width:200px;')); ?>
</div>
<div class="col-md-12 form-inline">
<?php echo $form->labelEx($model,'like',array('style'=>'padding-top:10px;margin-left:19px;')); ?>
<?php echo $form->textField($model,'like',array('class'=>'form-control input-xs','disabled'=>'disabled','size'=>30,'style'=>'text-align:center;')); ?>
</div>

<div class="col-md-12 form-inline">
<?php echo $form->labelEx($model,'dislike',array('style'=>'padding-top:10px;margin-left:6px;')); ?>
<?php echo $form->textField($model,'dislike',array('class'=>'form-control input-xs','disabled'=>'disabled','size'=>30,'style'=>'text-align:center;')); ?>
</div>
  </div>
  </div>
 </div>
 <div id="publish" class="tab-pane fade">
   <br/>
  <div class="col-md-12 form-inline">
  <table class="published">
  <tr>
  <td><?php echo $form->labelEx($model,'create_time'); ?></td>
  <td><?php echo $form->textField($model,'create_time',array('value'=>JDF::jdate("Y /m /d - H:i",$model->create_time),'class'=>'form-control bg-color input-xs', 'disabled'=>'disabled','size'=>20)); ?></td>
  <td><?php echo $form->labelEx($model,'create_user'); ?></td>
       <td><?php 
        empty($model->create_user)? $model->create_user=1:$model->create_user ;
        echo $form->textField($model,'create_user',array('value'=>$model->create->name,'class'=>'form-control bg-color input-xs', 'disabled'=>'disabled','size'=>20)); ?>
  </td>
  </tr>
  <tr>
  <td><?php echo $form->labelEx($model,'modified_time'); ?>
        </td>
  <td><?php echo $form->textField($model,'modified_time',array('value'=>JDF::jdate("Y /m /d - H:i",$model->modified_time),'class'=>'form-control bg-color input-xs', 'disabled'=>'disabled','size'=>20)); ?></td>
  <td><?php echo $form->labelEx($model,'modified_user'); ?>
       <?php 
        empty($model->modified_user)? $model->modified_user=1:$model->modified_user ; ?>
        </td>
  <td><?php echo $form->textField($model,'modified_user',array('value'=>$model->modified->name,'class'=>'form-control bg-color input-xs', 'disabled'=>'disabled','size'=>20)); ?></td>
  </tr>
  <tr>
  <td><?php echo $form->labelEx($model,'publish_up'); ?></td>
  <td><?php 
     $this->widget('ext.jalaliCalendar.jalaliCalendar', array(
  'model'=>$model,
  'attribute'=>'publish_up',
  'options'=>array(
  'button'=>'date_btn',
  'ifFormat'=> '%Y,%m,%d ',
  'dateType'=>'jalali'
  ),
  'htmlOptions'=>array(
  'class'=>'form-control bg-color input-xs',
  'style'=>' text-align: right;',
  ),
  ));
  ?>
</td>
  <td><?php echo $form->labelEx($model,'publish_down'); ?></td>
  <td>
  <?php 
     $this->widget('ext.jalaliCalendar.jalaliCalendar', array(
  'model'=>$model,
  'attribute'=>'publish_down',
  'options'=>array(
  'button'=>'date_btn',
  'ifFormat'=> '%Y,%m,%d ',
  'dateType'=>'jalali'
  ),
  'htmlOptions'=>array(
  'class'=>'form-control bg-color input-xs',
  'style'=>'text-align: right;',
  ),
  ));
  ?>
  </td>
  </tr>
  <tr>
  <td><?php echo $form->labelEx($model,'reference'); ?></td>
  <td><?php echo $form->textField($model,'reference',array('class'=>'form-control input-xs bg-color','size'=>20,'maxlength'=>50)); ?></td>
  <td><?php echo $form->labelEx($model,'urls'); ?></td>
  <td><?php echo $form->textField($model,'urls',array('class'=>'form-control input-xs bg-color','maxlength'=>250)); ?></td>
  </tr>
  </table>
  </div>
 </div>
 <div id="meta" class="tab-pane fade">
   <br/>
  <div class="col-md-12">
   <div class="col-md-6 form-inline">
<?php echo $form->labelEx($model,'metadesc'); ?>
<?php echo $form->textArea($model,'metadesc',array('class'=>'bg-color','rows'=>4,'cols'=>50,'size'=>60,'maxlength'=>1024)); ?>
</div>
<div class="col-md-6 form-inline">
<?php echo $form->labelEx($model,'metakey'); ?>
<?php echo $form->textArea($model,'metakey',array('class'=>'bg-color','rows'=>4,'cols'=>50,'size'=>60,'maxlength'=>2048)); ?>
</div>
</div>
 </div>
</div>


<?php $this->endWidget(); ?>

</div><!-- form -->
کد خطا رو کامل بگذارین. اینکه فقط بگین مقدار نمیگیره کمکی نمیکنه.
استاد کد خطای خاصی ندارم فقط وقتی به ذخیره سازی مدل میرسه میگه که مثلا عنوان وارد نشده
این هم کد مدل
class Content extends CActiveRecord
{
   /**
    * @return string the associated database table name
    */
   public function tableName()
   {
       return '{{content}}';
   }

   /**
    * @return array validation rules for model attributes.
    */
   public function rules()
   {
       // NOTE: you should only define rules for those attributes that
       // will receive user inputs.
       return array(
           array('title, create_time, modified_time, modified_user, publish_up, publish_down', 'required'),
           array('category_id, create_time, create_user, modified_time, modified_user, like, dislike, publish_up, publish_down, featured, confirmed', 'numerical', 'integerOnly'=>true),
           array('title, alias', 'length', 'max'=>255),
           array('language', 'length', 'max'=>7),
           array('reference', 'length', 'max'=>50),
           array('access, hits', 'length', 'max'=>11),
           array('introtext, fulltext, images, urls, metakey, metadesc, attributes', 'safe'),
           // The following rule is used by search().
           // @todo Please remove those attributes that should not be searched.
           array('id, title, alias, introtext, fulltext, category_id, create_time, create_user, modified_time, modified_user, like, dislike, publish_up, publish_down, images, urls, metakey, metadesc, featured, attributes, language, reference, access, hits, confirmed', 'safe', 'on'=>'search'),
       );
   }

   /**
    * @return array relational rules.
    */
   public function relations()
   {
       // NOTE: you may need to adjust the relation name and the related
       // class name for the relations automatically generated below.
       return array(
           'category' => array(self::BELONGS_TO, 'Category', 'category_id'),
           'createUser' => array(self::BELONGS_TO, 'User', 'create_user'),
           'modifiedUser' => array(self::BELONGS_TO, 'User', 'modified_user'),
       );
   }

   /**
    * @return array customized attribute labels (name=>label)
    */
   public function attributeLabels()
   {
       return array(
           'id' => 'ID',
           'title' => 'Title',
           'alias' => 'Alias',
           'introtext' => 'Introtext',
           'fulltext' => 'Fulltext',
           'category_id' => 'Category',
           'create_time' => 'Create Time',
           'create_user' => 'Create User',
           'modified_time' => 'Modified Time',
           'modified_user' => 'Modified User',
           'like' => 'Like',
           'dislike' => 'Dislike',
           'publish_up' => 'Publish Up',
           'publish_down' => 'Publish Down',
           'images' => 'Images',
           'urls' => 'Urls',
           'metakey' => 'Metakey',
           'metadesc' => 'Metadesc',
           'featured' => 'Featured',
           'attributes' => 'Attributes',
           'language' => 'Language',
           'reference' => 'Reference',
           'access' => 'Access',
           'hits' => 'Hits',
           'confirmed' => 'Confirmed',
       );
   }

   /**
    * Retrieves a list of models based on the current search/filter conditions.
    *
    * Typical usecase:
    * - Initialize the model fields with values from filter form.
    * - Execute this method to get CActiveDataProvider instance which will filter
    * models according to data in model fields.
    * - Pass data provider to CGridView, CListView or any similar widget.
    *
    * @return CActiveDataProvider the data provider that can return the models
    * based on the search/filter conditions.
    */
   public function search()
   {
       // @todo Please modify the following code to remove attributes that should not be searched.

       $criteria=new CDbCriteria;

       $criteria->compare('id',$this->id);
       $criteria->compare('title',$this->title,true);
       $criteria->compare('alias',$this->alias,true);
       $criteria->compare('introtext',$this->introtext,true);
       $criteria->compare('fulltext',$this->fulltext,true);
       $criteria->compare('category_id',$this->category_id);
       $criteria->compare('create_time',$this->create_time);
       $criteria->compare('create_user',$this->create_user);
       $criteria->compare('modified_time',$this->modified_time);
       $criteria->compare('modified_user',$this->modified_user);
       $criteria->compare('like',$this->like);
       $criteria->compare('dislike',$this->dislike);
       $criteria->compare('publish_up',$this->publish_up);
       $criteria->compare('publish_down',$this->publish_down);
       $criteria->compare('images',$this->images,true);
       $criteria->compare('urls',$this->urls,true);
       $criteria->compare('metakey',$this->metakey,true);
       $criteria->compare('metadesc',$this->metadesc,true);
       $criteria->compare('featured',$this->featured);
       $criteria->compare('attributes',$this->attributes,true);
       $criteria->compare('language',$this->language,true);
       $criteria->compare('reference',$this->reference,true);
       $criteria->compare('access',$this->access,true);
       $criteria->compare('hits',$this->hits,true);
       $criteria->compare('confirmed',$this->confirmed);

       return new CActiveDataProvider($this, array(
           'criteria'=>$criteria,
       ));
   }

   /**
    * Returns the static model of the specified AR class.
    * Please note that you should have this exact method in all your CActiveRecord descendants!
    * @param string $className active record class name.
    * @return Content the static model class
    */
   public static function model($className=__CLASS__)
   {
       return parent::model($className);
   }
}
البته یه نکته رو من یادم رفتم برم
من تاریخ ها رو با timestamp کار می کنم
برای تاریخ انتشار اومدم در قسمت beforsave از کد زیر استفاده کردم
$publish_up = explode(',',$this->publish_up);
 $publish_down = explode(',',$this->publish_down);
$publish_up= JDF::jalali_to_gregorian($publish_up[0],$publish_up[1],$publish_up[2] ,'-');
$publish_down= JDF::jalali_to_gregorian($publish_down[0],$publish_down[1],$publish_down[2] ,'-');
$date = new DateTime($publish_up);
$this->publish_up =  $date->getTimestamp();
$date = new DateTime($publish_down);
$this->publish_down =  $date->getTimestamp();
بخاطر این می تونه باشه
این هم مقادیری که پست میشه
Array
(
    [title] => تست
    [alias] => 
    [fulltext] => 
    [category_id] => 1
    [featured] => 1
    [confirmed] => 1
    [publish_up] => 1394,05,12 
    [publish_down] => 1394,05,14 
    [reference] => 
    [urls] => 
    [metadesc] => 
    [metakey] => 
)
خوب این اشتباهه الان. باید تمام اینها عناصر یه آرایه با اندیس Content باشن. شما POST_$ رو خروجی گرفتین یا ['POST['Content_$ رو ؟
من ['POST['Content_$ رو خروجی گرفتم POST_$ این ارایه رو به من میده
Array
(
    [yt0] => ذخیره و بستن
    [Content] => Array
        (
            [title] => تست
            [alias] => 
            [fulltext] => 
            [category_id] => 1
            [featured] => 1
            [confirmed] => 1
            [publish_up] => 1394,05,13 
            [publish_down] => 1394,05,22 
            [reference] => 
            [urls] => 
            [metadesc] => 
            [metakey] => 
        )

)
تمام این فیلدها رو توی مدل دارین؟ متن کامل خطا رو بگذارین.
(13-05-1394، 12:38 ب.ظ)ADMIN نوشته: [ -> ]تمام این فیلدها رو توی مدل دارین؟ متن کامل خطا رو بگذارین.

پیغام خطا رو ضمیمه کردم عکس رو
 
این هم کد مدل من که یک سری تغییرات روش انجام دادم
<?php

/**
* This is the model class for table "{{content}}".
*
* The followings are the available columns in table '{{content}}':
* @property integer $id
* @property string $title
* @property string $alias
* @property string $introtext
* @property string $fulltext
* @property integer $category_id
* @property integer $create_time
* @property integer $create_user
* @property integer $modified_time
* @property integer $modified_user
* @property integer $like
* @property integer $dislike
* @property integer $publish_up
* @property integer $publish_down
* @property string $images
* @property string $urls
* @property string $metakey
* @property string $metadesc
* @property integer $featured
* @property string $attributes
* @property string $language
* @property string $reference
* @property string $access
* @property string $hits
* @property integer $confirmed
*
* The followings are the available model relations:
* @property Category $category
* @property User $createUser
* @property User $modifiedUser
*/
class Content extends ContentActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return '{{content}}';
}

/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
           array('title', 'required'),
           array('category_id, create_time, create_user, modified_time, modified_user, like, dislike, publish_up, publish_down, featured, confirmed', 'numerical', 'integerOnly'=>true),
           array('title, alias', 'length', 'max'=>255),
           array('language', 'length', 'max'=>7),
           array('reference', 'length', 'max'=>50),
           array('access, hits', 'length', 'max'=>11),
           array('introtext, fulltext, images, urls, metakey, metadesc, attributes,, create_time, modified_time, modified_user, publish_up, publish_down', 'safe'),
           // The following rule is used by search().
           // @todo Please remove those attributes that should not be searched.
           array('id, title, alias, introtext, fulltext, category_id, create_time, create_user, modified_time, modified_user, like, dislike, publish_up, publish_down, images, urls, metakey, metadesc, featured, attributes, language, reference, access, hits, confirmed', 'safe', 'on'=>'search'),
       );
}

/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'category' => array(self::BELONGS_TO, 'Category', 'category_id'),
'create' => array(self::BELONGS_TO, 'User', 'create_user'),
'modified' => array(self::BELONGS_TO, 'User', 'modified_user'),
);
}

/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'شناسه',
'title' => 'عنوان',
'alias' => 'نام مستعار',
'introtext' => 'Introtext',
'fulltext' => 'توضیحات',
'category_id' => 'مجموعه',
'create_time' => 'تاریخ ایجاد',
'create_user' => 'نویسنده',
'modified_time' => 'تاریخ ویرایش',
'modified_user' => 'ویرایشگر',
'like' => 'پسند',
'dislike' => 'نا پسند',
'publish_up' => 'آغاز انتشار',
'publish_down' => 'پایان انتشار',
'images' => 'عکس',
'urls' => 'لینک',
'metakey' => 'کلیدواژه متا',
'metadesc' => 'توضیحات متا',
'featured' => 'ویژه',
'attributes' => 'خواص',
'language' => 'ربان',
'reference' => 'مرجع',
'access' => 'دسترسی',
'hits' => 'بازدیدها',
'confirmed' => 'تایید',
);
}

/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('id',$this->id);
$criteria->compare('title',$this->title,true);
$criteria->compare('alias',$this->alias,true);
$criteria->compare('introtext',$this->introtext,true);
$criteria->compare('fulltext',$this->fulltext,true);
$criteria->compare('category_id',$this->category_id);
$criteria->compare('create_time',$this->create_time);
$criteria->compare('create_user',$this->create_user);
$criteria->compare('modified_time',$this->modified_time);
$criteria->compare('modified_user',$this->modified_user);
$criteria->compare('like',$this->like);
$criteria->compare('dislike',$this->dislike);
$criteria->compare('publish_up',$this->publish_up);
$criteria->compare('publish_down',$this->publish_down);
$criteria->compare('images',$this->images,true);
$criteria->compare('urls',$this->urls,true);
$criteria->compare('metakey',$this->metakey,true);
$criteria->compare('metadesc',$this->metadesc,true);
$criteria->compare('featured',$this->featured);
$criteria->compare('attributes',$this->attributes,true);
$criteria->compare('language',$this->language,true);
$criteria->compare('reference',$this->reference,true);
$criteria->compare('access',$this->access,true);
$criteria->compare('hits',$this->hits,true);
$criteria->compare('confirmed',$this->confirmed);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}

/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return Content the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
میتونید تیم ویور بدین؟