Answer the question
In order to leave comments, you need to log in
Can't find page in Yii?
protected function findModel($id)
{
if (($model = Article::findOne($id)) !== null) {
return $model;
} else
throw new NotFoundHttpException('The requested page does not exist.');
}
public function actionSetImage($id)
{
$model = new ImageUpload;
if(Yii::$app->request->isPost)
{
$article = $this->findModel($id);
// var_dump($article->title);die;
$file = UploadedFile::getInstance($model, 'image');
$model->uploadedFile($file);
// var_dump(strtolower(md5(uniqid($file->baseName)) . '.' . $file->extension));
// $article->saveImage( $model->uploadedFile($file));
}
return $this->render('image', ['model'=>$model]);
}
}
Answer the question
In order to leave comments, you need to log in
many reasons, guess what? Well, let's go over the main ones:
1 the urlManager is not configured correctly
2 the id is not passed or the non-existing one is passed and it works
throw new NotFoundHttpException('The requested page does not exist.');
$arr_id = [];
foreach ($row as $value) {
if (isset($arr_id[$value['id']])) {
$arr_id[$value['id']] += $value['num'];
continue;
}
$arr_id[$value['id']] = $value['num'];
}
$row = [];
foreach ( $arr_id as $key => $value) {
$row[] = [
'id' => $key;
'num' => $value;
];
}
You can, in short, do it for a kid, like this
$result = array_reduce($input, function($acc, $i) {
if (isset($acc[$i['id']])) $acc[$i['id']]['num'] += $i['num'];
else $acc[$i['id']] = $i;
return $acc;
}, array());
// если нужен неассоциативный массив
$result = array_values($result);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question