/** * fake for test */ public function findOne($con = null) { if (true === $this->bySlug) { $book = new Book(); $book->setId(1); $book->setName('My Book'); $book->setSlug('my-book'); return $book; } return null; }
function handlePUT() { $conn = Connection::startConnection(); parse_str(file_get_contents("php://input"), $data); header('Content-type: application/json'); $book = new Book(); $book->setName($data['name']); $book->setAuthor($data['author']); $book->setDesc($data['opis']); $book->updateBook($conn, $data['id']); Connection::stopConnecion($conn); }
public function findOrCreateOne($book_name) { # Attempt to find book $book = BookQuery::create()->filterByName($book_name)->findOne(); # Return or create book if ($book) { return $book; } else { $book = new Book(); $book->setName($book_name)->save(); return $book; } }
public function setName($newName) { parent::setName($newName . " - wersja cyfrowa"); }
<?php trait NameTrait { private $name; public function getName() { return $this->name; } public function setName($name) { return $this->name = $name; } } class Book { use NameTrait; } $book = new Book(); $book->setName('PHP Cookbook'); print $book->getName();