'<button onClick="DeleteImg('.$img->id.')"
dataType: 'html',
public function actionDelimage(){
// например так
print_r(Yii::$app->reqiest->post);
$id = Yii::$app->request->post('id');
$model = ProductImg::findOne($id);
$model->delete();
return true;
}
public function actionDelimage(){
if(Yii::$app->request->isAjax){
$id = Yii::$app->request->post('id');
if(($model = ProductImg::findOne($id)) !== null){
$model->delete();
return true;
}
else{
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
$answer = [];
while($row = $query->fetch(PDO::FETCH_OBJ)) {
$answer = ['name' => $row->name]
}
echo json_encode($answer)
success: function (data) {
var response = jQuery.parseJSON(data);
console.log(response);
// например добавить информацию об имени в div с id result
$('#result').text(response.name)
}
$result = '';
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
$result = "<option>".$row['fullname'] . '</option>';
}
<div class="viewing-wrapper">
<div class="viewing-container">
<div class="viewing-title">
Выберите абоненета из списка
</div>
<div class="viewing-list">
<div class="viewing-select-wrap">
<select class="viewing-select">
<?= $result ?>
</select>
<button class="button btn-show">Показать</button>
</div>
</div>
</div>
</div>
$arr = [
'first' => [
'name1' => 'a','name2' => 'b', 'name3' => 'c'
],
'second' => [
'name1' => 'd','name2' => 'e', 'name3' => 'f'
]
];
$result = [];
foreach ($arr as $key => $value) {
$result[] = $value;
}
print_r($result);
Array
(
[0] => Array
(
[name1] => a
[name2] => b
[name3] => c
)
[1] => Array
(
[name1] => d
[name2] => e
[name3] => f
)
)
$this->registerJs("
$(function(){
alert('test')
})
", View::POS_END);
<div class="col-lg-6">
<?= $form->field($model, 'type')->textInput() ?>
<?= $form->field($model, 'number')->textInput() ?>
<?= $form->field($model, 'region')->textInput(['maxlength' => true]) ?>
</div>
<div class="col-lg-6">
<?= $form->field($model, 'type')->textInput() ?>
<?= $form->field($model, 'number')->textInput() ?>
<?= $form->field($model, 'region')->textInput(['maxlength' => true]) ?>
</div>
var target = '#a1';
var targetLink = $('a').attr('href');
if(target == targetLink){
/******/
}
"autoload": {
"psr-4": {
"app\\": ""
}
}
namespace app\core;
class Test
{
//******
}
$form->field($model, 'status')->dropDownList(
[
'Активный' => ['Админ', 'Модератор', 'Пользователь'],
'Отключён' => ['За нарушения', 'Самостоятельно']
],
[
'prompt' => 'Выбрать статус'
])
Model::loadMultiple
вместо $model->load()
'name' => $peoples[$i]['name'] ?? null, // php >= 7.0
$query = Category::find()
->select(['*', 'product_count' => new \yii\db\Expression('COUNT(products.id)')])
->joinWith('products', false)
->groupBy('{{%categories}}.id')
SELECT `username`, DATEDIFF(FROM_UNIXTIME(`updated_at`), FROM_UNIXTIME(`created_at`)) AS `date_diff` FROM `user`
Array
(
[0] => Array
(
[username] => admin
[date_diff] => 261
)
[1] => Array
(
[username] => Denis
[date_diff] => 73
)
[2] => Array
(
[username] => Vitaliy
[date_diff] => 80
)
[3] => Array
(
[username] => Elena
[date_diff] => 78
)
[4] => Array
(
[username] => Boris
[date_diff] => 0
)
[5] => Array
(
[username] => Daniel
[date_diff] => 0
)
[6] => Array
(
[username] => Vladimir
[date_diff] => 42
)
[7] => Array
(
[username] => Vasya
[date_diff] => 0
)
[8] => Array
(
[username] => Anton
[date_diff] => 0
)
[9] => Array
(
[username] => Nicolay
[date_diff] => 5
)
)
SELECT `username`, DATEDIFF(CURDATE(), FROM_UNIXTIME(`created_at`)) AS `date_diff` FROM `user`
Array
(
[0] => Array
(
[username] => admin
[date_diff] => 794
)
[1] => Array
(
[username] => Denis
[date_diff] => 616
)
[2] => Array
(
[username] => Vitaliy
[date_diff] => 515
)
[3] => Array
(
[username] => Elena
[date_diff] => 315
)
[4] => Array
(
[username] => Boris
[date_diff] => 215
)
[5] => Array
(
[username] => Daniel
[date_diff] => 200
)
[6] => Array
(
[username] => Vladimir
[date_diff] => 175
)
[7] => Array
(
[username] => Vasya
[date_diff] => 150
)
[8] => Array
(
[username] => Anton
[date_diff] => 149
)
[9] => Array
(
[username] => Nicolay
[date_diff] => 149
)
)