agavi/documentation — Issue #2: Multiple errors in documentation
Author: agavi
Created: 2012-02-09 03:23:56+00:00
State: open
Labels: error

Going through:
http://agavi.org/docs/tutorial/index.html

Provided SQL for "Bloggie" sample application is wrong. Tables created are: authors, categories, posts, comments ... but SQL statements in models refer to "admin_users" instead of "authors". Indexes/keys for "posts" table fail due to max key length within MySQL, presumably because the 'title' column is too long.

Code provided for "bloggie" is also incorrect. Provided code is:

```php
/**
* Retrieve 20 last posts.
*
* Selects the post summary, category name and author's screen name
* @return array Array of posts (id, title, posted, author_name, category_name)
*/

public function findFrontPagePosts()
{
// Obtain the connection identifier from our base class
// This works out to $this->context->getDatabaseManager()->getConnection()

$conn = $this->getPdo();

$sql = 'SELECT p.id, p.title, p.posted , a.screen_name AS author_name, c.name AS category_name
FROM posts p
LEFT JOIN admin_users a ON p.author_id = a.id
LEFT JOIN categories c ON p.category_id = c.id
ORDER BY posted DESC LIMIT 20';

return $conn->query($sql)->fetchAll();
}

/**
* Fetch a post by ID
*
* Retrieve a post record by given ID
* @param integer $id ID of the requested post
* @return array Post contents (all post fields, category_name, author_name)
*/

public function findPostById($id)
{
$conn = $this->getPdo();

$sth = $conn->prepare('SELECT p.*, a.screen_name AS author_name, c.name AS category_name
FROM posts p
LEFT JOIN admin_users a ON p.author_id = a.id
LEFT JOIN categories c ON p.category_id = c.id
WHERE p.id = ? LIMIT 1');
$sth->execute(array($id));

return $sth->fetch(PDO::FETCH_ASSOC);
}
```

however PHP/apache's error.log reports getPDO calls as unknown and I had to substitute in " $conn = $this->context->getDatabaseManager()->getDatabase()->getConnection(); " to make sample application work.

*(Originally posted to Trac as ticket #862 on 2008-09-19T21:24:48+00:00 by steve@…)*