Answer the question
In order to leave comments, you need to log in
Why didn't safeOnly in setAttributes work in Yii?
Good afternoon,
There is a Bid model with a certain number of properties that are not in the database, but are necessary in afterSave
class Bid extends ActiveRecord
{
public $adressFrom;
public $adressTo;
public $placeFrom;
public $placeTo;
public $categoryCargo;
public $timeStart;
public $timeFinish;
public $placeStart;
public $placeFinish;
...
public function rules()
{
return
[
...
['placeStart, placeFinish, adressStart, adressFinish, timeStart, timeFinish, categoryCargo, placeFrom, placeTo, adressFrom, adressTo, description, description_en, description_kz', 'safe'],
...
...
if(isset($_POST['Bid']))
{
$model->setAttributes($_POST['Bid'], false); // safeOnly
//My::printArr($_POST['Bid']);
My::printArr($model->attributes);
// die();
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
...
My::printArr($model->attributes);
Array
(
[urgency] => 2
[wish_price] => 5000
[description] =>
[id] =>
[customer_id] =>
[driver_id] =>
[views] =>
[status] =>
[name] =>
[name_kz] =>
[name_en] =>
[name_alias] =>
[description_en] =>
[description_kz] =>
[meta_d] =>
[meta_k] =>
[order_sort] =>
[sys_date] =>
[sys_date_update] =>
[sys_user] =>
[exist] =>
[shifr] =>
[name_full] =>
[name_full_kz] =>
)
<?php echo $form->labelEx($model,'adressFrom'); ?>
<?php echo $form->textField($model,'adressFrom',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'adressFrom'); ?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question