I just found a problem with my project. It's simply not saving data in database.
I couldn't find where is the problem, so please help to solve this problem.
my controller codes
public function actionCreate()
{
$model = new Ideyalar;
// $this->performAjaxValidation($model);
if(isset($_POST['Ideyalar']))
{
$model->attributes=$_POST['Ideyalar'];
$model->istifade = "1";
$model->idcontact = Yii::app()->user->getId();
if($model->save()){
$command = Yii::app()->db->createCommand();
$command->insert ('mqrup', array(
'idperson'=> Yii::app()->user->getId(),
'idideya'=>$model->idideya)
);
$command->update ('ideyalar',
['status'=>1],
'idideya=:i', [':i'=>$model->idideya]
);
$this->redirect(array('viewm','id'=>$model->idideya));
}
}
$this->render('create',array('model'=>$model));
}
public function actionViewm ($id)
{
$model1 = Ekspertiza::model()->idresult;
$sql = Yii::app()->db->createCommand()
->select ('e.idideya, urey, azerreal, elmireal, resrent')
->from ('exresult e')
->join ('ideyalar i', 'e.idideya=i.idideya')
->where ('e.idideya=:ei', [':ei'=>$id])
->queryAll();
$dataProvider = new CArrayDataProvider($seqele, [
'keyField'=>'idideya',
'sort'=> [
'attributes' => [
'idideya', 'urey', 'azerreal', 'elmireal', 'resrent'
],
],
]);
$this->render('viewm',['model'=>$this->loadModel($id), 'model1'=>$model1, 'dataProvider' => $dataProvider]);
}
create.php (view file)
<br><br>
<h4 style="margin-left:4%;">Yeni ideya</h4>
<div id="ger">
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'ideyalar-form',
));
?>
<p class="note-1"><em><span class="required">*</span> qeyd olunmuş sahələr mütləq doldurulmalıdır.</em></p><br>
<span id="ideya-yerror"><?php echo $form->errorSummary($model); ?></span>
<br>
<div class="ideya-div">
<?php echo $form->labelEx($model,'iddil'); ?>
</div>
<br>
<div class="ideya-div-1">
<?php echo $form->dropDownList($model, 'iddil',
CHtml::listData(Yii::app()->db->createCommand()
->select('iddil, dilad')
->from('diller')->queryAll() ,
'iddil', 'dilad'), array('options' => array($model->iddil =>array('selected'=>true)))); ?>
</div>
<br>
<div class="ideya-div"><?php echo $form->labelEx($model,'ideyaad'); ?></div><br>
<div class="ideya-div-1">
<?php echo $form->textField($model,'ideyaad',array('size'=>60,'maxlength'=>255)); ?>
</div>
<br>
<div class="ideya-div"><?php echo $form->labelEx($model,'idnettip'); ?></div><br>
<div class="ideya-div-1">
<?php echo $form->dropDownList($model, 'idnettip',
CHtml::listData(Yii::app()->db->createCommand()
->select('idnettip, nettip')
->from('nettip')->queryAll() ,
'idnettip', 'nettip'), array('options' => array($model->idnettip =>array('selected'=>true)))); ?>
</div>
<br>
<div class="ideya-div"><?php echo $form->labelEx($model,'mezmunu'); ?></div><br>
<div class="ideya-div-2">
<?php echo $form->textArea($model,'mezmunu',array('rows'=>6, 'cols'=>50)); ?>
</div>
<br>
<div class="ideya-div"><?php echo $form->labelEx($model,'xulase'); ?></div><br />
<div class="ideya-div-2">
<?php echo $form->textArea($model,'xulase'); ?>
</div>
<br>
<div class="ideya-div"><?php echo $form->labelEx($model,'patent'); ?></div><br>
<div class="ideya-div-1">
<?php echo $form->radioButtonList($model, 'patent',
array(1 => 'Var', 0=>'Yoxdur'), array('labelOptions'=>array('style'=>'display:inline'),
)); ?>
</div>
<br>
<div class="ideya-div"><?php echo $form->labelEx($model,'patentm'); ?></div><br>
<div class="ideya-div-2">
<?php echo $form->textArea($model,'patentm',array('rows'=>6, 'cols'=>50)); ?>
</div>
<br>
<div class="ideya-div"><?php echo $form->labelEx($model,'muddet'); ?></div><br>
<div class="ideya-div-1">
<?php echo $form->textField($model,'muddet'); ?>
</div>
<br>
<div class="ideya-div"><?php echo $form->labelEx($model,'vesait'); ?></div><br>
<div class="ideya-div-1">
<?php echo $form->textField($model,'vesait'); ?>
</div>
<br>
<div class="ideya-div"><?php echo $form->labelEx($model,'innova'); ?></div><br>
<div class="ideya-div-2">
<?php echo $form->textArea($model,'innova',array('rows'=>6, 'cols'=>50)); ?>
</div>
<br>
<div class="ideya-div"><?php echo $form->labelEx($model,'rivalry'); ?></div><br>
<div class="ideya-div-2">
<?php echo $form->textArea($model,'rivalry',array('rows'=>6, 'cols'=>50)); ?>
</div>
<br>
<div class="ideya-div"><?php echo $form->labelEx($model,'sosial'); ?></div><br>
<div class="ideya-div-2">
<?php echo $form->textArea($model,'sosial',array('rows'=>6, 'cols'=>50)); ?>
</div>
<br>
<div class="ideya-div"><?php echo $form->labelEx($model,'market'); ?></div><br>
<div class="ideya-div-2">
<?php echo $form->textArea($model,'market',array('rows'=>6, 'cols'=>50)); ?>
</div>
<br>
<div class="ideya-div"><?php echo $form->labelEx($model,'strategy'); ?></div><br>
<div class="ideya-div-2">
<?php echo $form->textArea($model,'strategy',array('rows'=>6, 'cols'=>50)); ?>
</div>
<br>
<div class="ideya-div">
<?php echo $form->labelEx($model,'niye'); ?>
</div><br>
<div class="ideya-div-2">
<?php echo $form->textArea($model,'niye',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'niye'); ?>
</div>
<br>
<div class="ideya-div-2">
<?php if($reference=="update")
{ ?>
<div class="ideya-div"><?php echo $form->labelEx($model,'texniki'); ?></div><br>
<div class="ideya-div-2">
<?php echo $form->textArea($model,'texniki',array('rows'=>6, 'cols'=>50, 'readonly' => true )); ?>
<?php echo $form->error($model,'texniki'); ?>
</div><br>
<div class="ideya-div"><?php echo $form->labelEx($model,'textarix'); ?></div><br>
<div class="ideya-div-1">
<?php echo $form->dateField($model,'textarix', array('readonly' => true ) ); ?>
<?php echo $form->error($model,'textarix'); ?>
</div><br>
<?php
}
?>
<div class="orta">
<input type="button" class="btn btn-danger" value="İmtina et" onclick="javascript:window.history.go(-1);return false;" />
<?php echo CHtml::submitButton($model->isNewRecord ? 'İdeyanı yarat' : 'Məlumatları yenilə', ['class'=>'btn btn-success']); ?>
</div>
<?php $this->endWidget(); ?>
</div>
viewm.php (another view file)
<?php $baseUrl=Yii::app()->request->baseUrl; ?>
<b><span id="comma"><h5>İdeya haqqında məlumatlar</h5></span></b><br /><br />
<div id="frame-l">
<?php
$this->widget('yiiwheels.widgets.detail.WhDetailView', array(
'data'=>$model,
'attributes'=>array(
'iddil'=> array(
'label' => $model->getAttributeLabel('iddil') ,
'type'=>'raw',
'value' => Yii::app()->db->createCommand()
->select('dilad')
->from('diller')->where('iddil = '.$model->iddil)->queryScalar()
),
'ideyaad',
'idnettip'=> array(
'label' => $model->getAttributeLabel('idnettip') ,
'type'=>'raw',
'value' => Yii::app()->db->createCommand()
->select('nettip')
->from('nettip')->where('idnettip = '.$model->idnettip)->queryScalar()
),
'mezmunu',
'patent'=>array(
'label' =>$model->getAttributeLabel('patent'),
'value'=> $model->idnettip == 0 ?"Yox":"Var",
),
'patentm',
'muddet',
'vesait',
'tarix',
'innova',
'rivalry',
'sosial',
'market',
'strategy',
'niye',
),
));
?>
</div>
<br><br><br><br>
<b><span id="comma"><h5>Ekspertiza qiymətləri</h5></span></b>
<div id="frame-r">
<?php
$this->widget('yiiwheels.widgets.grid.WhGridView', [
'id'=>'ideyalar-grid',
'dataProvider'=> $dataProvider ,
'ajaxUpdate'=>true,
'responsiveTable'=>true,
'fixedHeader'=>true,
'headerOffset'=>40,
'type'=>'striped bordered',
'columns'=>[
[
'name'=>'elmireal',
'header'=>'Elmi reallıq'
],
[
'name'=>'azerreal',
'header'=>'Lokal şəraitə uyğunluq'
],
[
'name'=>'resrent',
'header'=>'Rentabellilik'
],
[
'class'=>'bootstrap.widgets.TbButtonColumn',
'template'=>'{view}',
'viewButtonUrl'=>'Yii::app()->createUrl("/ideyalar/reyler", array("id"=>$data["idideya"]))',
'viewButtonOptions'=>['target'=>'_blank'],
'header'=>'Əməliyyatlar',
'headerHtmlOptions'=>[
'width'=>10,
'style'=>'color: white'
],
],
]
]);
?>
<input type="button" class="btn btn-info" value="Şəxsi səhifə" onclick="javascript:window.history.go(-2);return false;" />
</div>
Ideyalar.php (model)
<?php
/**
* This is the model class for table "ideyalar".
*
* The followings are the available columns in table 'ideyalar':
* @property integer $idideya
* @property integer $iddil
* @property string $ideyaad
* @property integer $idnettip
* @property string $mezmunu
* @property string $xulase
* @property string $patent
* @property string $patentm
* @property integer $muddet
* @property double $vesait
* @property string $tarix
* @property string $innova
* @property string $rivalry
* @property string $sosial
* @property string $market
* @property string $strategy
* @property string $niye
* @property string $istifade
* @property string $status
* @property integer $idtex
* @property string $texniki
* @property string $textarix
* @property integer $idishchi
* @property integer $view_count
* @property integer $idcontact
*/
class Ideyalar extends CActiveRecord
{
public function tableName()
{
return 'ideyalar';
}
public function rules()
{
return array(
array('iddil, ideyaad', 'required'),
array('iddil, idnettip, muddet, idtex, idishchi, view_count, idcontact', 'numerical', 'integerOnly'=>true, 'min'=>0),
array('vesait', 'numerical'),
array('ideyaad', 'length', 'max'=>255),
array('xulase', 'length', 'max'=>NULL),
array('patent, istifade, status', 'length', 'max'=>1),
array('ideyaad', 'unique'),
);
}
public function relations()
{
return array(
);
}
public function attributeLabels()
{
return array(
'iddil' => 'İdeyanın təqdim olunduğu dil',
'ideyaad' => 'İdeya adı',
'idnettip' => 'Gözlənilən nəticənin tipi',
'mezmunu' => 'İdeyanın məzmunu',
'patent' => 'İdeya üzrə patentlər yaxud ixtira şəhadətnamələri varmı?',
'patentm' => 'Əgər ideya üzrə patentlər yaxud ixtira şəhadətnamələri varsa, onlar haqqında məlumat',
'muddet' => 'Müddət (aylarla)',
'xulase' => 'İdeyanın xülasəsi',
'vesait' => 'Tələb olunan ümumi vəsait (min manatla)',
'tarix' => 'Daxil edilmə tarix',
'innova' => 'İdeyanın yeniliyi nədən ibarətdir?',
'rivalry' => 'Rəqabətliliyi (üstünlüyü)',
'sosial' => 'Sosial əhəmiyyəti',
'market' => 'Hansı bazar üçün nəzərdə tutulur?',
'strategy' => 'Marketinq strategiyası',
'niye' => 'Niyə məhz bu kollektiv təklif olunan ideyanı həyata keçirməlidir?',
'idtex' => 'Texniki ekspertizanın gedişi',
'texniki' => 'Texniki ekspertiza rəyi',
'textarix' => 'Textarix',
'view_count' => 'Baxılma sayı',
'idcontact' => 'Əlaqələndirici şəxs',
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('idideya',$this->idideya);
$criteria->compare('iddil',$this->iddil);
$criteria->compare('ideyaad',$this->ideyaad,true);
$criteria->compare('idnettip',$this->idnettip);
$criteria->compare('mezmunu',$this->mezmunu);
$criteria->compare('xulase',$this->xulase,true);
$criteria->compare('patent',$this->patent,true);
$criteria->compare('patentm',$this->patentm,true);
$criteria->compare('muddet',$this->muddet);
$criteria->compare('vesait',$this->vesait);
$criteria->compare('tarix',$this->tarix,true);
$criteria->compare('innova',$this->innova,true);
$criteria->compare('rivalry',$this->rivalry,true);
$criteria->compare('sosial',$this->sosial,true);
$criteria->compare('market',$this->market,true);
$criteria->compare('strategy',$this->strategy,true);
$criteria->compare('niye',$this->niye,true);
$criteria->compare('istifade',$this->istifade,true);
$criteria->compare('status',$this->status,true);
$criteria->compare('idtex',$this->idtex);
$criteria->compare('texniki',$this->texniki,true);
$criteria->compare('textarix',$this->textarix,true);
$criteria->compare('idishchi',$this->idishchi);
$criteria->compare('view_count',$this->view_count);
$criteria->compare('idcontact',$this->idcontact);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
These codes must insert data to 2 tables: mqrup
and ideyalar
, and also updates a column in table ideyalar
(which named as status
).
With inserting data to mqrup
and updating column status
I have no problem...
But some of the information of the isn't inserted to ideyalar
table.
When the user creates the new idea the following columns should update:
iddil, ideyaad, idnettip, xulase, muddet, vesait, istifade, status
with these columns I don't have any problem. All data'll insert correctly.
But only
mezmunu, patent, patentm, innova, rivalry, sosial, market, strategy, niye
columns are not 'effected'.
I couldn't find where is the problem (with codes and/or program algorithm).
If you know the solution, please help me.
I think I can explain what's my problem and what I actually need... If I couldn't explain, sorry for bad English.
P.S: when I update the existing idea, I again and again fill problematic fields, it's again and again not inserts data to db.
Thanks and best regards.
I'm not sure this applies to all the missing updates but...
You can't massively assign attributes that do not have an associated validation in the model's rules()
method as these are seen as unsafe:
$model->attributes=$_POST['Ideyalar'];
Will not update unsafe attributes from the $_POST
array.
You can add a safe
rule for the extra attributes, or (better) add validation for them.