$(function(){
function Testing(url, form){
var file = '';
var formdata = new FormData(form[0]);
formdata.forEach(function(item, i, arr){
if(i == 'files'){
formdata.append(item.name, item)
}
})
$.ajax({
url: url,
type: 'POST',
processData: false,
contentType: false,
data: formdata,
success: function(data){
console.log(data)
}
})
}
$('#form-data').on('submit', function(e){
e.preventDefault();
Testing('upload.php', $(this))
})
})
$new_model->from_form = ($model->from_form - 2);
public function beforeSave($insert)
{
if(parent::beforeSave($insert)){
if((self::getOldAttribute('from_form') > 2){
$this->from_form = ($this->from_form - 2)
}
return true;
}
return false;
}
php yii
и посмотрите список команд, который доступен. Возможно Вы неверно вводите команду. rules => [
'<_c:[\w]+>/<_a:[\w]+>/<id:\d+>' => '<_c>/view'
]
<?= $form->field($model, 'country_id')->dropDownList(ArrayHelper::map(Countries::getAllName(), 'id', 'name_ru'),
[
'prompt' => 'Выбрать страну...',
'onchange' => '
$.post(
"'.Url::toRoute('ajax/list').'",
{id : $(this).val()},
function(data){
$("select#regions").html(data).attr("disabled", false)
}
)
'
]);
//это взаимосвязанный выпадающий список, куда будет подставлен результат работы ajajx
<?= $form->field($model, 'region_id')->dropDownList(ArrayHelper::map(Regions::getAllName(), 'id', 'name_ru'),
[
'prompt' => 'Выбрать регион...',
'id' => 'regions',
'disabled' => $model->isNewRecord ? 'disabled' : false
])
public function actionList()
{
if(Yii::$app->request->isAjax)
{
$id = (int)Yii::$app->request->post('id');
$regions = Regions::find()
->where('status=:status',[':status' => Regions::STATUS_ACTIVE])
->andWhere('country_id=:id', [':id' => $id])
->orderBy('name_ru')
->all();
foreach($regions as $region){
$this->option .= '<option value="'.$region->id.'">'.$region->name_ru.'</option>';
}
}
return $this->option;
}
public function attributeLabels()
{
return ArrayHelper::merge(parent::attributeLabels(),[
'newPassword' => 'Новый пароль',
'newPasswordRepeat' => 'Повторить новый пароль'
]);
}
use yii\behaviors\TimestampBehavior;
public function behaviors()
{
return [
TimestampBehavior::className()
];
}
public function getVideos()
{
return $this->owner->hasMany($this->className, [$this->attribute => 'id'])->where([/* тут Ваше условие */]);
}
string()->notNull();
if($transfer->save()){
// какое-то действие
}
else{
// показать все ошибки
}
$transfer->created_at = time();
use yii\behaviors\TimestampBehavior;
public function behaviors()
{
return [
TimestampBehavior::className()
];
}