当前位置: 首页>>代码示例>>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;未经允许,请勿转载。