Y
Y
Yulyul2018-09-13 14:20:47
Yii
Yulyul, 2018-09-13 14:20:47

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

3 answer(s)
M
Maxim Timofeev, 2018-09-13
@Yulul

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.');

3 it's not about this code at all

C
Centrino, 2015-03-27
@DANAB

$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;
        ];
}

It could be prettier, but this is just a quick example.

T
Timofey, 2015-03-27
@mr_T

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 question

Ask a Question

731 491 924 answers to any question