Ticket #862 (closed defect: fixed)

Opened 2 months ago

Last modified 8 weeks ago

Multiple errors in documentation

Reported by: steve@… Owned by: mikeseth
Priority: highest Milestone: 1.0
Component: documentation Version: HEAD-1.0
Severity: normal Keywords:
Cc: noah.fontes@… Patch attached: no

Description

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:

/**

  • 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.

Attachments

Change History

Changed 2 months ago by impl

  • cc noah.fontes@… added
  • owner changed from david to mikeseth
  • version changed from 0.11.3 to 1.0-HEAD
  • milestone set to 1.0

Changed 2 months ago by markus.lervik@…

Yes, the title column is too long. The tutorial uses

title varchar(256) collate utf8_unicode_ci NOT NULL

Which ought to be varchar(255), I'm assuming, because a unicode char in the BMP (which should allow for pretty much any chars in any alphabet) uses three bytes, and 256 * 3 = 768. MySQL allows KEYs to be up to 767 bytes as far as I can tell.

Changed 2 months ago by marc.christenfeldt@…

In http://agavi.org/docs/tutorial/topics/creating-models.html a project model 'Posts' is created:

bloggie$ agavi project-model-create

Model name: Posts
     [copy] Copying 1 file to /home/nfontes/bloggie/app/models

Later in this tutorial (http://agavi.org/docs/tutorial/topics/setting-up-actions.html) the code tries to use the 'Posts' model from the module 'Public' - which is does not exist.

    // Obtain the Posts model from this module
    $m = $this->context->getModel('Posts', 'Public');

Changed 8 weeks ago by mikeseth

  • priority changed from normal to highest

SQL schema discrepancy and title length is corrected in trunk

Changed 8 weeks ago by mikeseth

corrected the location of the Posts model (should be in Public) module

Changed 8 weeks ago by mikeseth

cleared up the example code and the topic regarding the base model

Changed 8 weeks ago by mikeseth

  • status changed from new to closed
  • resolution set to fixed

[2950], [2951] closes this ticket

Add/Change #862 (Multiple errors in documentation)

Author



Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.