本文整理汇总了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数据
}
示例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();
}
}
示例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;