本文整理汇总了PHP中Books::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Books::save方法的具体用法?PHP Books::save怎么用?PHP Books::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Books
的用法示例。
在下文中一共展示了Books::save方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create()
{
$userid = Auth::user()->userid;
// return Input::get("");exit();
$book = new Books();
$book->title = Input::get('title');
$book->description = Input::get('description');
$book->category = Input::get('genre');
$book->sub_category = "none";
$book->author = Input::get('author');
$book->condition = Input::get('cond');
$book->location = Input::get('loc');
$book->cover = Input::get('image');
$book->snippet = "none";
$book->language = Input::get('lang');
$book->popularity = "none";
$book->quantity = Input::get('quantity');
$book->expected_price = Input::get('rate');
$book->purpose = Input::get('purpose');
$book->added_by = $userid;
//The USERID
$book->save();
//Add Book to Personal Info of the User
$tn = $userid . "_books";
DB::table($tn)->insert(array('title' => Input::get('title'), 'author' => Input::get("author"), 'condition' => Input::get('cond'), 'location' => Input::get('loc'), 'language' => Input::get('lang'), 'quantity' => Input::get('quantity'), 'expected_price' => Input::get('rate'), 'avlb' => 1));
}
示例2: actionAdd
public function actionAdd()
{
Yii::app()->getClientScript()->registerCoreScript('jquery');
Yii::app()->getClientScript()->registerCoreScript('jquery.ui');
$cs = Yii::app()->clientScript;
$cs->registerCssFile('/js/datepicker/css/' . 'datepicker.css');
$cs->registerScriptFile('/js/' . 'books.js');
//
$book = new Books();
$command = Yii::app()->db->createCommand();
if (isset($_POST['Books'])) {
$book->attributes = $_POST['Books'];
if ($book->validate()) {
$book->save();
if (isset($_POST['add_auth']) && !empty($_POST['add_auth'])) {
$criteria = new CDbCriteria();
$criteria->compare('lastname', $_POST['add_auth']);
$add_author = Authors::model()->find($criteria);
//If author exists
if (!empty($add_author)) {
//insert link book-author to link table
$command->insert('lt_books_authors', array('author_id' => $add_author->id, 'book_id' => $book->id));
}
}
$this->actionIndex();
return true;
}
}
$this->render('edit', array('model' => $book));
}
示例3: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
// check if method is post
if (Request::isMethod('post')) {
$input = Input::all();
$validator = Validator::make($input, array('title' => 'required', 'author' => 'required', 'genre' => 'required'));
// check if data is validated
if ($validator->fails()) {
// redirect with errors if the given data did not pass validation
return Redirect::to('create')->withErrors($validator);
}
$book = new Books();
$book->title = Input::get('title');
$book->author = Input::get('author');
$book->genre = Input::get('genre');
$book->description = Input::get('description');
$book->published = Input::get('published');
$book->format = Input::get('format');
// check if an image is added.
if (Input::hasFile('image')) {
$destinationPath = public_path() . '/uploads/';
$original_filename = Input::file('image')->getClientOriginalName();
$extension = Input::file('image')->getClientOriginalExtension();
$filename = md5(uniqid() . $original_filename);
// save file
Input::file('image')->move($destinationPath, $filename . '.' . $extension);
$book->image = $filename . '.' . $extension;
}
$book->save();
return Redirect::to('/')->with('success', Lang::get('labels.bookadded'));
}
}
示例4: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
// validate
// read more on validation at http://laravel.com/docs/validation
$rules = array('title' => 'required', 'author' => 'required', 'year' => 'required', 'isbn' => 'required', 'price' => 'required', 'stock' => 'required');
$validator = Validator::make(Input::all(), $rules);
// process the login
if ($validator->fails()) {
return Redirect::to('books/create');
} else {
// imagen
$filename = Input::get('isbn') . '.jpg';
$path = public_path() != '' ? public_path() : '/public/cover';
$destinationPath = $path;
if (Input::file('cover') != "") {
Input::file('cover')->move($destinationPath, $filename);
}
var_dump($path);
// store
$books = new Books();
$books->title = Input::get('title');
$books->cover = $filename;
$books->author = Input::get('author');
$books->year = Input::get('year');
$books->isbn = Input::get('isbn');
$books->price = Input::get('price');
$books->stock = Input::get('stock');
$books->save();
// redirect
Session::flash('message', $destinationPath);
return Redirect::to('books/create');
}
}
示例5: actionCreate
public function actionCreate()
{
$book = new Books();
if (isset($_REQUEST['Books'])) {
$book->setAttributes($_REQUEST['Books']);
}
if (isset($_REQUEST['save']) && $_REQUEST['save']) {
$book->save();
}
$this->render('create', array('book' => $book));
}
示例6: store
public function store()
{
$validator = Validator::make(Input::all(), Books::$rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator);
} else {
$books = new Books();
$books->bname = Input::get('bname');
$books->bauthor = Input::get('bauthor');
$books->bedition = Input::get('bedition');
$books->phone = Input::file('image');
$books->save();
return Redirect::route('books.index');
}
}
示例7: actionSample
public function actionSample()
{
$json = file_get_contents('E:\\xampp\\htdocs\\books\\protected\\data\\data.json');
$arr = json_decode($json, true);
foreach ($arr["Books"] as $item) {
$model = new Books();
$model->book_description = $item['Description'];
$model->book_name = $item['Title'];
$model->book_image = $item['Image'];
$model->book_author = 'Anonymous';
$model->book_publisher = 'It Ebook';
$model->book_year = 2009;
$model->created_at = time();
$model->updated_at = time();
$model->status = 1;
$model->save(FALSE);
}
}
示例8: addBook
public function addBook($book_name, $book_author, $book_year, $book_publisher, $book_image, $book_description)
{
$model = new Books();
$model->book_name = $book_name;
$model->book_author = $book_author;
$model->book_year = $book_year;
$model->book_publisher = $book_publisher;
$model->book_image = $book_image;
$model->created_at = time();
$model->updated_at = time();
$model->status = 1;
$model->book_description = $book_description;
if ($model->save(FALSE)) {
return TRUE;
} else {
return FALSE;
}
}
示例9: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Books();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Books'])) {
$model->attributes = $_POST['Books'];
foreach ($model->attributes as $key => &$atr) {
if (empty($atr)) {
$model->{$key} = null;
}
}
if ($model->save()) {
if (!empty($_FILES['Books']['name']['ext1']) && $model->delete_img1 == '0') {
$model->ext1 = CUploadedFile::getInstance($model, 'ext1');
if ($model->ext1) {
$ext1 = $model->ext1->extensionName;
$file = Yii::app()->basePath . '/../images/' . mb_strtolower('Books') . '/' . $model->id . "_1." . $ext1;
$model->ext1->saveAs($file);
$model->ext1 = $ext1;
$model->save();
}
} else {
if ($model->delete_img1 == '1') {
$filename = Yii::app()->basePath . '/../images/' . mb_strtolower('Books') . '/' . $model->id . "." . $model->ext1;
if (file_exists($filename)) {
unlink($filename);
}
$model->ext1 = '';
$model->save();
}
}
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
}
$this->render('create', array('model' => $model));
}
示例10: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
// validate
// read more on validation at http://laravel.com/docs/validation
$rules = array('title' => 'required', 'author' => 'required', 'year' => 'required', 'isbn' => 'required', 'price' => 'required', 'stock' => 'required');
$validator = Validator::make(Input::all(), $rules);
// process the login
if ($validator->fails()) {
return Redirect::to('books/create');
} else {
// store
$books = new Books();
$books->title = Input::get('title');
$books->author = Input::get('author');
$books->year = Input::get('year');
$books->isbn = Input::get('isbn');
$books->price = Input::get('price');
$books->stock = Input::get('stock');
$books->save();
// redirect
Session::flash('message', 'Guardado exitosamente en la base de datos!');
return Redirect::to('books/create');
}
}
示例11: unlink
unlink($_GET['image']);
} else {
$errors[] = "Imaginea nu a fost salvata";
}
}
}
if (!$errors) {
$book = new Books();
$book->name = $_POST['name'];
$book->category_id = $_POST['category'];
$book->author = $_POST['author'];
$book->price = $_POST['price'];
if (isset($target)) {
$book->image = $target;
}
if ($book->save($_GET['id']) == 1) {
$_SESSION['succes'] = "Cartea \"{$book->name}\" a fost editata!";
header("Location: books.php");
} else {
header("Location: books.php");
}
}
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
}
}
?>
<div class="panel panel-default">
<div class="panel-heading"><?php
echo $title;
示例12: import
public static function import($jsonDatas, $keep_ids = FALSE, $logged = FALSE)
{
global $_CONFIG;
if (!$logged) {
die('You are not authorized to import books.');
}
$datas = json_decode($jsonDatas, TRUE);
if (!isset($datas['books']) || !isset($datas['posters'])) {
return FALSE;
}
$booksDatas = $datas['books'];
$images = $datas['posters'];
$id = time();
$i = 0;
$books = new Books($logged);
foreach ($booksDatas as $book) {
$id = $keep_ids && isset($book['id']) ? $book['id'] : $id;
while (isset($books[$id])) {
$id--;
}
$inputs = array('id' => $id, 'title' => isset($book['title']) ? trim(self::html_escaped($book['title'])) : NULL, 'author' => isset($book['author']) ? trim(self::html_escaped($book['author'])) : NULL, 'summary' => isset($book['summary']) ? checkNewLineContent(preg_replace('#<br( /)?>#', '', $book['summary'])) : NULL, 'publisher' => isset($book['publisher']) ? trim(self::html_escaped($book['publisher'])) : NULL, 'status' => isset($book['status']) && $book['status'] != NULL ? Book::SEEN : NULL, 'note' => isset($book['note']) ? checkRatingNote($book['note'], isset($book['status']) && $book['status'] != NULL ? Book::SEEN : NULL) : NULL, 'read_date' => isset($book['read_date']) ? checkInputDate($book['read_date']) : NULL, 'review' => isset($book['review']) ? checkNewLineContent(preg_replace('#<br( /)?>#', '', $book['review'])) : NULL, 'genre' => isset($book['genre']) ? checkGenre($book['genre']) : NULL, 'publication_year' => isset($book['release_date']) ? checkInputYear($book['release_date']) : NULL, 'pages' => isset($book['pages']) ? checkPages($book['pages']) : NULL, 'country' => isset($book['country']) ? checkCountry($book['country']) : NULL, 'link_website' => isset($book['link_website']) ? checkLink($book['link_website']) : NULL, 'link_image' => NULL);
if (empty($inputs['title']) && empty($inputs['author']) && empty($inputs['summary'])) {
continue;
}
if (function_exists('imagecreatefromjpeg') && !empty($images[$i])) {
$image = explode(',', $images[$i]);
if (!isset($image[1])) {
continue;
}
$imported = file_put_contents($_CONFIG['images'] . '/' . $id . '.jpg', base64_decode($image[1]));
if ($imported == false) {
continue;
}
$inputs['link_image'] = $_CONFIG['images'] . '/' . $id . '.jpg';
}
$books[$id] = $inputs;
$i++;
}
$books->save();
return TRUE;
}
示例13: actionAddNewBook
public function actionAddNewBook()
{
$transaction = Yii::app()->db->beginTransaction();
try {
$book_model = new Books();
$book_attributes = $_POST['Books'];
$book_attributes['creation_date'] = date('Y-m-d H:i:s');
$book_model->attributes = $book_attributes;
if ($book_model->validate()) {
if ($book_model->save()) {
$last_insert_book_id = $book_model->id;
$relation_array = array();
foreach ($_POST['author_list'] as $author) {
$relation_array[] = array('book_id' => $last_insert_book_id, 'author_id' => $author);
}
$builder = Yii::app()->db->schema->commandBuilder;
$command = $builder->createMultipleInsertCommand('authors_books_relation', $relation_array);
$command->execute();
$transaction->commit();
Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, 'Новая книга добавлена');
$this->redirect(array('library/tabs&tab_id=books'));
}
}
} catch (CDbException $e) {
$transaction->rollback();
}
}