本文整理汇总了PHP中Book::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::delete方法的具体用法?PHP Book::delete怎么用?PHP Book::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Book
的用法示例。
在下文中一共展示了Book::delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* @return bool
* @throws Exception
*/
public function process()
{
$bookModel = new Book();
if (!$bookModel->load($this->data) || !$bookModel->validate()) {
throw new Exception('Invalid data!');
}
return $bookModel->delete();
}
示例2: remove
function remove()
{
$id = $this->uri->segment(3);
$obj = new Book();
$obj->where('id', $id)->get();
$obj->delete();
echo $obj->check_last_query();
}
示例3: testDelete
function testDelete()
{
$title = "Anathem";
$test_book = new Book($title);
$test_book->save();
$title2 = "Snow Crash";
$test_book2 = new Book($title2);
$test_book2->save();
$test_book->delete();
$this->assertEquals([$test_book2], Book::getAll());
}
示例4: Book
function test_delete()
{
$title = "Three Blind Mice";
$test_book = new Book($title);
$test_book->save();
$title2 = "Chicken Dog";
$test_book2 = new Book($title2);
$test_book2->save();
$test_book->delete();
$result = Book::getAll();
$this->assertEquals([$test_book2], $result);
}
示例5: Book
function test_delete()
{
//Arrange
$title = "Sea Wolf";
$test_book = new Book($title);
$test_book->save();
$title2 = "Eye of the World";
$test_book2 = new Book($title2);
$test_book2->save();
//Act
$test_book2->delete();
$result = Book::getall();
//Assert
$this->assertEquals([$test_book], $result);
}
示例6: testDeleteDependentWithConditions
/**
* testDeleteDependentWithConditions method
*
* @return void
*/
public function testDeleteDependentWithConditions()
{
$this->loadFixtures('Cd', 'Book', 'OverallFavorite');
$Cd = new Cd();
$Book = new Book();
$OverallFavorite = new OverallFavorite();
$Cd->delete(1);
$result = $OverallFavorite->find('all', array('fields' => array('model_type', 'model_id', 'priority')));
$expected = array(array('OverallFavorite' => array('model_type' => 'Book', 'model_id' => 1, 'priority' => 2)));
$this->assertTrue(is_array($result));
$this->assertEquals($expected, $result);
$Book->delete(1);
$result = $OverallFavorite->find('all', array('fields' => array('model_type', 'model_id', 'priority')));
$expected = array();
$this->assertTrue(is_array($result));
$this->assertEquals($expected, $result);
}
示例7: testDelete
function testDelete()
{
//Arrange
$title = "Little Cat";
$id = 1;
$test_book = new Book($title, $id);
$test_book->save();
$name = "Ben";
$id = 1;
$test_author = new Author($name, $id);
$test_author->save();
//Act
$test_book->addAuthor($test_author);
$test_book->delete();
//Assert
$this->assertEquals([], $test_author->getBooks());
}
示例8: testSpeed
//.........这里部分代码省略.........
$ret = $bk2->validate();
// Now trying some more complex validation.
$auth1 = new Author();
$auth1->setFirstName("Hans");
// last name required; will fail
$bk1->setAuthor($auth1);
$rev1 = new Review();
$rev1->setReviewDate("08/09/2001");
// will fail: reviewed_by column required
$bk1->addReview($rev1);
$ret2 = $bk1->validate();
$bk2 = new Book();
$bk2->setTitle("12345678901");
// passes
$auth2 = new Author();
$auth2->setLastName("Blah");
//passes
$auth2->setEmail("some@body.com");
//passes
$auth2->setAge(50);
//passes
$bk2->setAuthor($auth2);
$rev2 = new Review();
$rev2->setReviewedBy("Me!");
// passes
$rev2->setStatus("new");
// passes
$bk2->addReview($rev2);
$ret3 = $bk2->validate();
// Testing doCount() functionality
// -------------------------------
$c = new Criteria();
$count = BookPeer::doCount($c);
// Testing many-to-many relationships
// ----------------------------------
// init book club list 1 with 2 books
$blc1 = new BookClubList();
$blc1->setGroupLeader("Crazyleggs");
$blc1->setTheme("Happiness");
$brel1 = new BookListRel();
$brel1->setBook($phoenix);
$brel2 = new BookListRel();
$brel2->setBook($dj);
$blc1->addBookListRel($brel1);
$blc1->addBookListRel($brel2);
$blc1->save();
// init book club list 2 with 1 book
$blc2 = new BookClubList();
$blc2->setGroupLeader("John Foo");
$blc2->setTheme("Default");
$brel3 = new BookListRel();
$brel3->setBook($phoenix);
$blc2->addBookListRel($brel3);
$blc2->save();
// re-fetch books and lists from db to be sure that nothing is cached
$crit = new Criteria();
$crit->add(BookPeer::ID, $phoenix->getId());
$phoenix = BookPeer::doSelectOne($crit);
$crit = new Criteria();
$crit->add(BookClubListPeer::ID, $blc1->getId());
$blc1 = BookClubListPeer::doSelectOne($crit);
$crit = new Criteria();
$crit->add(BookClubListPeer::ID, $blc2->getId());
$blc2 = BookClubListPeer::doSelectOne($crit);
$relCount = $phoenix->countBookListRels();
$relCount = $blc1->countBookListRels();
$relCount = $blc2->countBookListRels();
// Removing books that were just created
// -------------------------------------
$hp = BookPeer::retrieveByPk($phoenix_id);
$c = new Criteria();
$c->add(BookPeer::ID, $hp->getId());
// The only way for cascading to work currently
// is to specify the author_id and publisher_id (i.e. the fkeys
// have to be in the criteria).
$c->add(AuthorPeer::ID, $hp->getId());
$c->add(PublisherPeer::ID, $hp->getId());
$c->setSingleRecord(true);
BookPeer::doDelete($c);
// Attempting to delete books by complex criteria
$c = new Criteria();
$cn = $c->getNewCriterion(BookPeer::ISBN, "043935806X");
$cn->addOr($c->getNewCriterion(BookPeer::ISBN, "0380977427"));
$cn->addOr($c->getNewCriterion(BookPeer::ISBN, "0140422161"));
$c->add($cn);
BookPeer::doDelete($c);
$td->delete();
AuthorPeer::doDelete($stephenson_id);
AuthorPeer::doDelete($byron_id);
$grass->delete();
PublisherPeer::doDelete($morrow_id);
PublisherPeer::doDelete($penguin_id);
$vintage->delete();
// These have to be deleted manually also since we have onDelete
// set to SETNULL in the foreign keys in book. Is this correct?
$rowling->delete();
$scholastic->delete();
$blc1->delete();
$blc2->delete();
}
示例9: testDelete
function testDelete()
{
//Arrange
$book_title = "Snow Crash";
$id = null;
$test_book = new Book($book_title, $id);
$test_book->save();
$book_title2 = "Ready Player One";
$id2 = null;
$test_book2 = new Book($book_title2, $id2);
$test_book2->save();
//Act
$test_book->delete();
//Assert
$this->assertEquals([$test_book2], Book::getAll());
}
示例10: Book
function test_delete()
{
//Arrange
$title = "World War Z";
$genre = "Horror";
$test_book = new Book($title, $genre);
$test_book->save();
$name2 = "Billy Bartle-Barnaby";
$genre2 = "2015-07-09";
$test_book2 = new Book($name2, $genre2);
$test_book2->save();
//Act
$test_book->delete();
//Assert
$result = Book::getAll();
$this->assertEquals($test_book2, $result[0]);
}
示例11: book_delete_form_submit
function book_delete_form_submit($data)
{
$book = new Book();
$delete = $book->delete($data['id']);
if ($delete['code'] == 200) {
return $data['id'];
} else {
return FALSE;
}
}
示例12: testDelete
function testDelete()
{
//Arrange
$book_name = "Intro to Art";
$test_book = new Book($book_name);
$test_book->save();
$book_name2 = "Everybody Poops";
$test_book2 = new Book($book_name2);
$test_book2->save();
$name = "Arty";
$test_author = new Author($name);
$test_author->save();
//Act
$test_book->addAuthor($test_author);
$test_book->delete();
//Assert
$this->assertEquals([], $test_author->getBooks());
}
示例13: save
/**
* Saves the book into de database.
* If the id isn't setted, automatically assigns one
*
**/
public function save(){
$update = false ;
$hasErrors = false;
if(!isset($this->userId))
$this->userId = 1; //TODO: Remove only for debugging user must be always setted (logged user)
$sql = "INSERT INTO ".table('books'). " (BookId, BookName, UserId) VALUES ($this->bookId,'$this->bookName',$this->userId)";
if (isset($this->bookId)) { // Edit book..
//Check if the the id is correct..
$res = mysql_query("SELECT BookId FROM ".table('books'). " where BookId=$this->bookId");
if(!$res){
$error = new GsError(302,"Error loading book.");
if($error->isDebugging()){
$error->addContentElement("BookId",$BookId);
$err = str_replace("'", '"', mysql_error());
$error->addContentElement("MySql Error",$err);
}
throw $error;
$hasErrors = true;
}
$row = mysql_fetch_object($res);
if (!$row) {
//ERROR: trying to save a book that does exist. Must have null value the bookid
if(!mysql_query($sql)){
$error = new GsError(302,"Error saving book. Book don't exists");
if($error->isDebugging()){
$error->addContentElement("BookId",$BookId);
$err = str_replace("'", '"', mysql_error());
$error->addContentElement("MySql Error",$err);
}
throw $error;
}
}else {
// OK: Delete.. and save it again
$update = true;
mysql_query("START TRANSACTION");
$book_tmp = new Book();
$book_tmp->load($this->bookId);
$book_tmp->delete(true);
if(!mysql_query($sql)){
$error = new GsError(302,"Error saving book. Book don't exists");
if($error->isDebugging()){
$error->addContentElement("BookId",$BookId);
$err = str_replace("'", '"', mysql_error());
$error->addContentElement("MySql Error",$err);
}
throw $error;
$hasErrors = true;
}
}
}else {
//SAVE AS...
$sql = "INSERT INTO ".table('books'). " (BookName, UserId) VALUES ('$this->bookName',$this->userId)";
$query = mysql_query($sql);
if($query)
$this->bookId= mysql_insert_id();
else{
$error = new GsError(302,"Error saving book.");
if($error->isDebugging()){
$error->addContentElement("BookId",$BookId);
$err = str_replace("'", '"', mysql_error());
$error->addContentElement("MySql Error",$err);
}
throw $error;
$hasErrors = true;
}
}
//COMMON CODE..
if(!$hasErrors){
foreach ($this->sheets as $sheet) {
$sheet->bookId = $this->bookId;
$hasErrors = $sheet->save();
}
}
if(!$hasErrors){
foreach ($this->fontStyles as $fontStyle) {
$fontStyle->bookId = $this->bookId;
$hasErrors = $fontStyle->save();
}
//.........这里部分代码省略.........
示例14: Book
if ($_POST['action'] == 'submit') {
if (isset($_POST['usertext'])) {
$text = $_POST['usertext'];
$book = new Book();
$book->add($text);
} else {
echo "sorry you have to enter name and comment";
}
} elseif ($_POST['action'] == 'like') {
if ($_POST['l_id']) {
$id = $_POST['l_id'];
$book = new Book();
$book->like($id);
}
} elseif ($_POST['action'] == 'delete') {
if ($_POST['d_id']) {
$id = $_POST['d_id'];
$book = new Book();
$book->delete($id);
}
} elseif ($_POST['action'] == 'update') {
if ($_POST['up_id']) {
if ($_POST['new_comment']) {
$new_comment = $_POST['new_comment'];
$id = $_POST['up_id'];
$book = new Book();
$book->update($id, $new_comment);
}
}
}
}
示例15: Book
function test_delete()
{
//Arrange
$title = "Whimsical Fairytales...and other stories";
$genre = "Fantasy";
$test_book = new Book($title, $genre);
$test_book->save();
$title2 = "The Secret Life of Garden Gnomes";
$genre2 = "Nonfiction";
$test_book2 = new Book($title2, $genre2);
$test_book2->save();
//Act
$test_book->delete();
//Assert
$result = Book::getAll();
$this->assertEquals($test_book2, $result[0]);
}