Got it working! 🍎

This commit is contained in:
Chris Smith
2025-02-19 21:43:44 +01:00
parent 658718ca06
commit 61e85ae9a2
20 changed files with 651 additions and 1200 deletions

View File

@@ -3,10 +3,14 @@
namespace frontend\controllers;
use common\models\Meal;
use frontend\models\MealForm;
use Yii;
use yii\data\ActiveDataProvider;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;
/**
* MealController implements the CRUD actions for Meal model.
@@ -21,8 +25,17 @@ class MealController extends Controller
return array_merge(
parent::behaviors(),
[
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
],
@@ -57,6 +70,28 @@ class MealController extends Controller
]);
}
public function actionUpload()
{
$model = new MealForm();
if (Yii::$app->request->isPost) {
$model->picture = UploadedFile::getInstance($model, 'picture');
if ($model->upload()) {
$meal = \Yii::$app->gemini->mealInquiry($model->filepath);
return $this->render('success', ['model' => $meal]);
}
}
return $this->render('upload', [
'model' => $model,
]);
}
public function actionSuccess()
{
return $this->render('success');
}
/**
* Displays a single Meal model.
* @param int $id ID