本文整理汇总了PHP中app\models\Item::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::save方法的具体用法?PHP Item::save怎么用?PHP Item::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Item
的用法示例。
在下文中一共展示了Item::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
public function update($id, Request $request)
{
$messages = [];
//rules to apply of each field
$rulesItem = array('name' => 'string|required', 'weight' => 'integer|required|min:0');
$validatorItem = Validator::make($request->all(), $rulesItem);
if ($validatorItem->fails()) {
foreach ($validatorItem->messages()->getMessages() as $key => $value) {
$messages[] = Lang::get('validator.global', ["name" => $key]);
}
$error = Constants::MSG_ERROR_CODE;
} else {
$name = $request->input('name');
$weight = $request->input('weight');
$item = Item::find($id);
if ($item == null) {
$messages[] = Lang::get('items.notFoundById', ['id' => $id]);
$error = Constants::MSG_ERROR_CODE;
} else {
$newItem = new Item();
$newItem->name = $name;
$newItem->weight = $weight;
$newItem->active = Constants::ACTIVE;
$newItem->save();
$item->active = Constants::ARCHIVED;
$item->save();
$error = Constants::MSG_OK_CODE;
$messages[] = Lang::get('items.modified');
}
}
if ($error == Constants::MSG_ERROR_CODE) {
return redirect()->back()->with(['messages' => $messages, 'error' => $error]);
}
return redirect()->route('items::viewAll')->with('error', $error)->with('messages', $messages);
}
示例2: actionCreate
/**
* Creates a new Item model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Item();
$modelPrice = new Price();
$modelPrice->tax = 12;
if ($model->load(Yii::$app->request->post()) && $model->validate() && $modelPrice->load(Yii::$app->request->post()) && $modelPrice->validate()) {
$transaction = $model->getDb()->beginTransaction();
try {
if (!$model->save(false)) {
throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($model->tableName())), 'msj' => print_r($model->getErrors(), true)]), 500);
}
if (!$modelPrice->save(false)) {
throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($modelPrice->tableName())), 'msj' => print_r($modelPrice->getErrors(), true)]), 500);
}
$modelItemPrice = new ItemPrice();
$modelItemPrice->item_id = $model->id;
$modelItemPrice->price_id = $modelPrice->id;
if (!$modelItemPrice->save(false)) {
throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($modelItemPrice->tableName())), 'msj' => print_r($modelItemPrice->getErrors(), true)]), 500);
}
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollBack();
throw $e;
}
return $this->redirect(['index']);
} else {
return $this->render('create', ['model' => $model, 'modelPrice' => $modelPrice]);
}
}
示例3: actionCreate
/**
* Creates a new Item model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Item();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例4: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$item = new Item();
$item->nombre_item = $request->nombre;
$item->tipo_item = $request->tipo;
$item->estado_item = $request->estado;
$item->concepto = $request->concepto;
$item->save();
return redirect('item');
}
示例5: store
/**
* Create an Item and it's derived class
*
* @param $inputs
* @param User $user
* @return Item
*/
public function store($inputs, $user)
{
$item = new Item();
$item->value = $inputs['value'];
$item->description = $inputs['description'];
$item->discovery_setting = $inputs['discovery_setting'];
$item->user_id = $user->id;
$item->save();
return $item;
}
示例6: actionCreate
/**
* Creates a new Item model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Item();
if ($model->load(Yii::$app->request->post())) {
$model->stock = $model->quantity;
if ($model->save()) {
return $this->redirect(['index']);
}
}
return $this->render('create', ['model' => $model]);
}
示例7: postEdit
public function postEdit($id)
{
$validator = Validator::make(Request::all(), ['name' => 'required', 'price' => 'required|numeric']);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator->errors());
}
$item = new Item($id);
$item->name = Request::get('name');
$item->description = Request::get('description');
$item->price = Request::get('price');
$item->save();
return redirect('item/' . $id);
}
示例8: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// ---------------------------------------------------------------------
// CONFERENCE 4
// ---------------------------------------------------------------------
$conference = Conference::find(4);
$item = ['name' => 'Laptop', 'quantity' => 1];
$item = new Item($item);
$item->conference()->associate($conference);
$item->save();
$item = ['name' => 'Projector', 'quantity' => 1];
$item = new Item($item);
$item->conference()->associate($conference);
$item->save();
}
示例9: save
/**
* 新商品
*/
public function save()
{
$item = new Item();
$item->cat_id = Input::get('cat_id');
$item->name = Input::get('name');
$item->sku = Input::get('sku');
$item->price = Input::get('price');
$destinationPath = "";
$fileName = date('');
if (Request::hasFile('logo')) {
$file = Request::file('logo');
Request::file('photo')->move($destinationPath, $fileName);
}
var_dump($file);
exit;
$item->save();
}
示例10: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Item();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if (Yii::$app->request->post('ajax') !== null) {
return \app\helpers\Response::send(200, $model);
}
//$model->pic->saveAs('/to/localFile');
return $this->redirect(array('admin', 'id' => $model->id));
}
if (Yii::$app->request->post('ajax') !== null) {
return \app\helpers\Response::send(501, $model->errors);
}
$model->sku = $model->maxId() + 1;
$model->parent_item_id = 0;
return $this->render('create', array('model' => $model));
}
示例11: store
/**
* Create an Item for a Conference.
*
* @param ItemRequest $request
* @param int $cid
* @return Response
*/
public function store(ItemRequest $request, $cid)
{
try {
$user = $this->isConferenceManager($request, $cid);
if (!$user) {
return response()->error(403, 'You are not a manager of this conference!');
}
$conference = Conference::find($cid);
if (!$conference) {
return response()->error(404, 'Conference Not Found');
}
$item = new Item($request->all());
$item->conference()->associate($conference);
$item->save();
return response()->success();
} catch (Exception $e) {
return response()->error();
}
}
示例12: register
public function register(Request $request)
{
$u = new Item();
$u->itemssubgroupid = $request->input('itemssubgroupid');
$u->code = $request->input('code');
$u->name = $request->input('name');
$u->quantity = $request->input('quantity');
$u->mesid = $request->input('mesid');
$u->price = $request->input('price');
if ($request->input('sstatus') == NULL) {
$u->sstatus = 0;
} else {
$u->sstatus = $request->input('sstatus');
}
$u->userid = $request->input('userid');
$u->save();
//echo 'successfully Inserted.';
return redirect('itemmaster');
}
示例13: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(ItemRequest $request)
{
//store
$item = new Item();
$item->name = Input::get('name');
$item->unit = Input::get('unit');
$item->remarks = Input::get('remarks');
$item->min_level = Input::get('min_level');
$item->max_level = Input::get('max_level');
$item->storage_req = Input::get('storage_req');
$item->user_id = Auth::user()->id;
try {
$item->save();
$url = session('SOURCE_URL');
return redirect()->to($url)->with('message', trans('messages.record-successfully-saved'))->with('activeitem', $item->id);
} catch (QueryException $e) {
\Log::error($e);
}
}
示例14: postUpload
public function postUpload()
{
$files = $this->flyLocal()->listContents();
foreach ($files as $file) {
if (preg_match('/.csv$/', $file['basename'])) {
$contents = $this->flyLocal()->readAndDelete($file['basename']);
$csv = Reader::createFromString($contents);
$rows = $csv->setOffset(1)->fetchAll();
foreach ($rows as $row) {
$item = new Item();
$item->date = strtotime($row[0]);
$item->category = $row[1];
$item->title = $row[2];
$item->location = $row[3];
$item->condition = $row[4];
$item->amount = $row[5];
$item->tax_name = $row[6];
$item->tax_amount = $row[7];
$item->save();
}
}
}
return redirect('admin');
}
示例15: addItem
public function addItem($bookID)
{
if ($this->petugas == null) {
header("Location: " . base . "/Auth");
exit;
}
$item = new Item();
$item->BookID = $bookID;
$item->save();
header("Location: " . base . "/Book/items/{$bookID}");
}