本文整理汇总了PHP中Book::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::save方法的具体用法?PHP Book::save怎么用?PHP Book::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Book
的用法示例。
在下文中一共展示了Book::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Book();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Book'])) {
$authordetails = Author::model()->findByAttributes(array('author_name' => $_POST['Book']['author']));
$publication = Publication::model()->findByAttributes(array('name' => $_POST['Book']['publisher']));
$model->attributes = $_POST['Book'];
if ($publication == NULL) {
$publisher = new Publication();
$publisher->name = $_POST['Book']['publisher'];
$publisher->save();
$model->publisher = $publisher->publication_id;
} else {
$model->publisher = $publication->publication_id;
}
if ($model->save()) {
//echo count($authordetails).$authordetails->auth_id; exit;
if ($authordetails) {
$model->author = $authordetails->auth_id;
$model->save();
} else {
$author = new Author();
$author->author_name = $_POST['Book']['author'];
$author->save();
$model->author = $author->auth_id;
$model->save();
}
$model->status = 'C';
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例2: testTicket2
public function testTicket2()
{
$obj = new Book();
$obj->set('name', 'yes2');
$obj->save();
$this->assertEqual($obj->get('name'), 'yes2');
$obj->save();
}
示例3: bookInsertion
function bookInsertion($title, $ISBN, $author)
{
$book = new \Book(['title' => $title, 'isbn' => $ISBN]);
$book->link('author', $author);
$book->save();
return $book;
}
示例4: add
public function add()
{
$rules = array('name' => 'required|unique:books,name', 'author' => 'required', 'date' => 'required', 'file' => 'mimes:jpeg,bmp,png');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
Session::put('msgfail', 'Invalid input.');
return Redirect::back()->withErrors($validator)->withInput();
} else {
$destinationPath = '';
$filename = '';
if (Input::hasFile('file')) {
$file = Input::file('file');
$destinationPath = public_path() . '/uploads/book/';
$filename = str_random(6) . '_' . $file->getClientOriginalName();
$uploadSuccess = $file->move($destinationPath, $filename);
}
$book_save = new Book();
$book_save->name = strip_tags(Input::get('name'));
$book_save->author = strip_tags(Input::get('author'));
$book_save->date = Input::get('date');
$book_save->file = $filename;
$book_save->save();
Session::put('msgsuccess', 'Successfully added book.');
return Redirect::back();
}
}
示例5: testFormatALotOfResults
public function testFormatALotOfResults()
{
$nbBooks = 50;
$con = Propel::getConnection(BookPeer::DATABASE_NAME);
Propel::disableInstancePooling();
$book = new Book();
for ($i = 0; $i < $nbBooks; $i++) {
$book->clear();
$book->setTitle('BookTest' . $i);
$book->save($con);
}
$stmt = $con->query('SELECT * FROM book');
$formatter = new PropelOnDemandFormatter();
$formatter->init(new ModelCriteria('bookstore', 'Book'));
$books = $formatter->format($stmt);
$this->assertTrue($books instanceof PropelOnDemandCollection, 'PropelOnDemandFormatter::format() returns a PropelOnDemandCollection');
$this->assertEquals($nbBooks, count($books), 'PropelOnDemandFormatter::format() returns a collection that counts as many rows as the results in the query');
$i = 0;
foreach ($books as $book) {
$this->assertTrue($book instanceof Book, 'PropelOnDemandFormatter::format() returns a collection of Model objects');
$this->assertEquals('BookTest' . $i, $book->getTitle(), 'PropelOnDemandFormatter::format() returns the model objects matching the query');
$i++;
}
Propel::enableInstancePooling();
}
示例6: create
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
// Fetch all request data.
$data = Input::only('title', 'genre', 'book_cover', 'book_public_state');
// Build the validation constraint set.
$rules = array('title' => array('required', 'min:3', 'max:100', 'unique:books'), 'genre' => array('alpha'), 'book_cover' => array('image'), 'book_public_state' => array('integer'));
// Create a new validator instance.
$validator = Validator::make($data, $rules);
if ($validator->passes()) {
$book = new Book();
$title = Input::get('title');
$book->title = $title;
// $date = new DateTime();
// $time = $date->format('Y-m-d-H-i-s');
//$book->slug = $time.'-'.Str::slug($title, '-');
$uniqid = str_shuffle(uniqid());
$book->slug = Str::slug($title, '-') . '-' . $uniqid;
$book->author_id = Sentry::getUser()->id;
$book->genre = Input::get('genre');
$book->secret_link = str_shuffle(uniqid());
$book->public_state = Input::get('book_public_state') ? 1 : 0;
//Book cover file handle
/*$file = Input::file('book_cover');
$destinationPath = 'uploads/';
$extension = $file->getClientOriginalExtension();
$filename = $title.'.'.$extension;
Input::file('book_cover')->move($destinationPath, $filename);*/
$book->save();
return Redirect::to('/dashboard')->with('global_success', 'Book added successfuly!');
}
return Redirect::to('/dashboard')->withInput()->withErrors($validator)->with('message', 'Validation Errors!');
}
示例7: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aCategory !== null) {
if ($this->aCategory->isModified() || $this->aCategory->isNew()) {
$affectedRows += $this->aCategory->save($con);
}
$this->setCategory($this->aCategory);
}
if ($this->aBook !== null) {
if ($this->aBook->isModified() || $this->aBook->isNew()) {
$affectedRows += $this->aBook->save($con);
}
$this->setBook($this->aBook);
}
if ($this->isNew()) {
$this->modifiedColumns[] = ArticlePeer::ID;
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = ArticlePeer::doInsert($this, $con);
$affectedRows += 1;
// we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setId($pk);
//[IMV] update autoincrement primary key
$this->setNew(false);
} else {
$affectedRows += ArticlePeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
if ($this->collAuthorArticles !== null) {
foreach ($this->collAuthorArticles as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
if ($this->collAttachments !== null) {
foreach ($this->collAttachments as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例8: createNewBook
public function createNewBook()
{
$book = new Book();
$book->Titel = Input::get("titel");
$book->User = Input::get("user_ID");
$book->save();
return View::make('createBook');
}
示例9: bookInsertion
function bookInsertion($title, $ISBN, $author)
{
$book = new \Book();
$book->title = $title;
$book->isbn = $ISBN;
$book->author()->associate($author);
$book->save();
return $book;
}
示例10: process
/**
* @return bool
* @throws Exception
*/
public function process()
{
$bookModel = new Book();
if ($bookModel->load($this->data) && $bookModel->validate()) {
$bookModel->save();
return (array) $bookModel;
}
throw new Exception('Invalid data!');
}
示例11: testUpdate
function testUpdate()
{
$book_name = "Siddhartha";
$test_book = new Book($book_name);
$test_book->save();
$test_book->setTitle("Peace Train");
$test_book->update();
$result = Book::getAll();
$this->assertEquals($test_book, $result[0]);
}
示例12: runBookInsertion
function runBookInsertion($i)
{
$book = new Book();
$book->title = 'Hello' . $i;
$book->isbn = '1234';
$book->price = $i;
$book->author = $this->authors[array_rand($this->authors)];
$book->save(false);
$this->books[] = $book;
}
示例13: save
function save()
{
$params = $this->input->post();
$obj = new Book();
foreach ($params as $key => $val) {
$obj->{$key} = $val;
}
$obj->save();
echo $this->db->insert_id();
}
示例14: runBookInsertion
function runBookInsertion($i)
{
$book = new Book();
$book->setTitle('Hello' . $i);
$book->setAuthorId($this->authors[array_rand($this->authors)]);
$book->setISBN('1234');
$book->setPrice($i);
$book->save($this->con);
$this->books[] = $book->getId();
}
示例15: testRemoveCopies
function testRemoveCopies()
{
$book_name = "Marakami";
$new_book = new Book($book_name);
$new_book->save();
Copies::setCopies($new_book, 8);
Copies::removeCopies($new_book, 5);
$result = Copies::getCopies($new_book);
$this->assertEquals(3, $result);
}