public function actionUpdateTest()
{
//get form model
$model= new formUpdateCollectionItem();
//get ar model
$model2 = $this->loadModel();
//form model attributes to selected ones from ar model
$model->attributes = $model2->collection[$_GET['index']];
$model->attributes['index'] = $_GET['index'];
if(isset($_POST['formUpdateCollectionItem']))
{
//doesn't set my data right
$model2['collection'][$_POST['index']]['name'] = $_POST['formUpdateCollectionItem']['name'];
$model2['collection'][$_POST['index']]['points'] = $_POST['formUpdateCollectionItem']['points'];
$model2->collection = serialize($model2['collection']);
if($model2->save())
echo("okeeeeee");
}
$this->render('updatetest', array('model'=>$model));
}
alright i changed the $_GET to $_POST, but no change…
the other parts of code:
<?php
class formUpdateCollectionItem extends CFormModel
{
public $index;
public $name;
public $points;
/**
* Declares the validation rules.
*/
public function rules()
{
return array(
// name, email, subject and body are required
array('name, points', 'required'),
);
}
/**
* Declares customized attribute labels.
* If not declared here, an attribute would have a label that is
* the same as its name with the first letter in upper case.
*/
public function attributeLabels()
{
return array(
'name'=>'Skill Name',
'points'=>'Skill Points',
);
}
}
<?php
$this->breadcrumbs=array(
'Serial Tests'=>array('index'),
$model->index=>array('view','index'=>$model->index),
'Update',
);
?>
<h1>Update serialTest <?php echo $model->index; ?></h1>
<ul class="actions">
<li><?php echo CHtml::link('List serialTest',array('index')); ?></li>
<li><?php echo CHtml::link('Create serialTest',array('create')); ?></li>
<li><?php echo CHtml::link('Manage serialTest',array('admin')); ?></li>
</ul><!-- actions -->
<div class="form">
<?php echo CHtml::beginForm(); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<div class="row">
<?php echo CHtml::activeHiddenField($model,'index'); ?>
<?php echo CHtml::activeLabelEx($model,'name'); ?>
<?php echo CHtml::activeTextField($model,'name'); ?>
<?php echo CHtml::activeLabelEx($model,'points'); ?>
<?php echo CHtml::activeTextField($model,'points'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Save'); ?>
</div>
<?php echo CHtml::endForm(); ?>
</div><!-- form -->
<?php
class serialTest extends CActiveRecord
{
/**
* The followings are the available columns in table 'serialTest':
* @var integer $id
* @var string $collection
*/
/**
* Returns the static model of the specified AR class.
* @return CActiveRecord the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'serialTest';
}
/**
* @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('collection', 'required'),
);
}
/**
* @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(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'Id',
'collection' => 'Collection',
);
}
public function getProfileSerial($userId)
{
$Criteria = new CDbCriteria();
$Criteria->condition = "id = :id";
$Criteria->params = array (':id' => $userId);
return self::model()->find($Criteria);
}
}
I hope this helps to find my problem :s