當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Food::save方法代碼示例

本文整理匯總了PHP中Food::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP Food::save方法的具體用法?PHP Food::save怎麽用?PHP Food::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Food的用法示例。


在下文中一共展示了Food::save方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionAdd_food

 public function actionAdd_food()
 {
     $food = new Food();
     $food->title = $_POST['title'];
     $food->content = $_POST['content'];
     $food->port = $_POST['port'];
     $food->save();
     //$this->redirect(Yii::app()->request->urlReferrer);
     echo 1;
     //                        echo CJSON::encode(array('title'=>$_POST['title'], 'area'=>$_POST['area'], 'port'=>$_POST['port']));//Yii 的方法將數組處理成json數據
 }
開發者ID:rocketyang,項目名稱:yii2,代碼行數:11,代碼來源:FoodController.php

示例2: store

 /**
  * Store a newly created resource in storage.
  * POST /foods
  *
  * @return Response
  */
 public function store()
 {
     // Validate input.
     $input = array('name' => Input::get('name'), 'serving' => Input::get('serving'), 'calories' => Input::get('calories'), 'fats' => Input::get('fats'), 'carbohydrates' => Input::get('carbohydrates'), 'proteins' => Input::get('proteins'));
     $rules = array('name' => 'required', 'serving' => array('required', 'numeric'), 'calories' => array('required', 'numeric'), 'fats' => array('required', 'numeric'), 'carbohydrates' => array('required', 'numeric'), 'proteins' => array('required', 'numeric'));
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         $messages = $validator->messages();
         return Redirect::back()->withErrors($messages)->withInput();
     }
     // Store the input in an entry.
     $food = new Food();
     $food->name = Input::get('name');
     $food->serving_size = Input::get('serving');
     $food->fats = Input::get('fats');
     $food->carbohydrates = Input::get('carbohydrates');
     $food->proteins = Input::get('proteins');
     $food->calories = Input::get('calories');
     if ($food->save()) {
         return Redirect::route('foods.index');
     } else {
         return Redirect::back()->withInput();
     }
 }
開發者ID:JustinMackenzie,項目名稱:meal-log,代碼行數:30,代碼來源:FoodsController.php

示例3: function

     return $response->write(json_encode($comments) . '     ');
 })->setName('food_comments');
 // yemek ekle
 $this->post('', function ($request, $response, $args) {
     $user = Token::where('token', '=', $request->getHeader('token')[0])->get()->first()->user();
     $newFood = json_decode($request->getBody());
     $food = new Food();
     $food->user_id = $user->user_id;
     $food->category_id = $newFood->category_id;
     $food->name = $newFood->name;
     $food->materials = $newFood->materials;
     $food->description = $newFood->description;
     $food->create_date = date("YmdHi");
     $food->last_update_date = date("YmdHi");
     try {
         $food->save();
         return $response->write(json_encode($food) . '     ');
     } catch (Illuminate\Database\QueryException $e) {
         return $response->write('{"msg": "ERR"}');
     }
 })->setName('food_create');
 // yemek güncelle
 $this->put('/{id:[0-9]+}', function ($request, $response, $args) {
     $newFood = json_decode($request->getBody());
     $user = Token::where('token', '=', $request->getHeader('token')[0])->get()->first()->user();
     $food = Food::find($args['id']);
     if ($food->user_id != $user->user_id) {
         return $response->write('{"msg":"Yetkisiz erişim"}');
     }
     $food->name = $newFood->name;
     $food->materials = $newFood->materials;
開發者ID:gokselpirnal,項目名稱:WhatTheFood-web,代碼行數:31,代碼來源:routes.php


注:本文中的Food::save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。