PHP Classes

File: examples/library/www/book_author_add.php

Recommend this page to a friend!
  Classes of Victor Bolshov   Tiny PHP ORM Framework   examples/library/www/book_author_add.php   Download  
File: examples/library/www/book_author_add.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Tiny PHP ORM Framework
Map objects to databases using composed queries
Author: By
Last change:
Date: 8 years ago
Size: 611 bytes
 

Contents

Class file image Download
<?php

use \library\Registry,
    \
library\Book;

include
__DIR__ . "/../bootstrap.php";

if (empty(
$_POST["book_id"])) {
    die(
"No book ID provided");
}

if (empty(
$_POST["author_id"])) {
    die(
"No author ID provided");
}

/** @var Book $book */
$book = Registry::persistenceDriver()->find((int) $_POST["book_id"], new Book());
if (!
$book) {
    die(
"Book ID #" . (int) $_POST["book_id"] . " not found");
}

if (
$book->hasAuthor($_POST["author_id"])) {
    die(
"This book already has this author");
}

$book->addAuthor($_POST["author_id"]);

header("Location: book_edit.php?id=" . (int) $_POST["book_id"]);