On Jan 22, 2011, at 22:42, websurfshop wrote:

> I have numerous authoritative books.  Each book is stored in a
> separate database table with each paragraph in the book as a separate
> record.  Like so.
> 
> id int,
> bookname varchar
> chapternumber tinyint
> paragraphnumber tinyint
> paragraphtext text

Really? You have a separate *table* for each book? Instead, I would have 
expected you to have a table "books" with columns like "id" (the book id) and 
"name" (the book name), and a table "paragraphs" with columns like "id" (the 
paragraph id), "book_id", and "text" (and whatever other columns you like).

Actually, perhaps you want to have a table "books" as above, then a table 
"chapters" with columns "id" (the chapter id), "order" (the order of this 
chapter in the book; what you were calling "chapternumber"), and maybe "name" 
(the chapter name or title); and then table "paragraphs" would have columns 
"id" (paragraph id), "chapter_id", "order" and "text".


> All thru the project I am required to display quoted paragraphs from
> these authoritative books, and would like to streamline as far a
> possible with a helper the calls.  Something like:
> 
> $this-CustomHelper->quoteText($id);
> 
> To display a formatted paragraph in the view across the project.  My
> confusion exists in exactly how to go about this in a proper way since
> each quoted paragraph involves a call to the database in a find.  And
> I would like to use a number of helper functions to not only properly
> format and link the quoted paragraph text, but also supply a link to
> the entire chapter, chapter neighbors, and even the entire book.
> 
> So since I am dealing with a call to the database does this logic
> belong in a behavior?  A component?  Or do I make the database call
> and all the formatting logic in a view helper?  Or some combination of
> the above?

I don't know the answer to your last paragraph, but based on a previous 
discussion in this group that was just had within the past 24 hours, you don't 
want your helper to be doing database queries. Database queries are the purview 
of your model. And you interact with your model from your controller. So your 
model should have a method that can return all the quotes you need for your 
page. Your controller asks the model to run that method and sends the resulting 
array into the view. The view then renders it by passing it to the helper.



-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to