`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
other fields...
CREATE TABLE `books` {
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`author_id` int(11) NOT NULL,
other fields...
http://jbenner.net/blog/understanding-cakephp-associations
On Oct 4, 4:48 am, "S/*\\L/*\\L/*\\M" <abdusal...@gmail.com> wrote:
> qwanta yes the relationship is that u mentioned.i had did these all
> things as u mention, but the error r stuck there and couldnt remove so
> 4..this error is not from table syntax nor from cake php..but as i
> think i didnt define foreign key properly.
> ->if i want to define a foreign key for {author_id} so what will be
> the syntax for this..tables r authors and books.
> thnx for ur time and help.
>
> On Oct 4, 12:56 am, qwanta <rgmic...@gmail.com> wrote:
>
> > Note also you have to have your tables defined according to the
> > CakePHP syntax. Each one should have an "id" key column. Then the Book
> > table should have an author_id field to link the author.
>
> > On Oct 3, 2:54 pm, qwanta <rgmic...@gmail.com> wrote:
>
> > > If it's a one to many relationship (author has many books, each book
> > > has one author):
>
> > > In Book Model you stick this:
> > > var $belongsTo = array ('Author');
>
> > > In Author Model:
> > > var $hasMany = array ('Book');
>
> > >http://book.cakephp.org/view/78/Associations-Linking-Models-Together
>
> > > I'd recommend going through these tutorials:
>
> > >http://www.sitepoint.com/article/application-development-cakephp/http...
>
> > > On Oct 3, 1:36 pm, "Abdus Salaam" <abdusal...@gmail.com> wrote:
>
> > > > thanx for ur time.
> > > > - ya u r rite that htmlhelper is easy way to genrate tables cell and
> > > > headers..
> > > > but i m trying to learn some code myself.. :p
> > > > - i m trying to made relationship b/w books and authors tables...i think its
> > > > relation is not make properly.
> > > > -how to make foreign key?..i think thats the problem.
> > > > thanx
>
> > > > On Fri, Oct 3, 2008 at 11:13 PM, qwanta <rgmic...@gmail.com> wrote:
>
> > > > > What you probably want to do is take a look at what you have in the
> > > > > $books array at the end of your controller. A quick and dirty way is
> > > > > to put a var_dump($books); as last statement in your controller
> > > > > function. The contents will then show up at the top of your view.
> > > > > Check if the ['Author']['name'] data is there.
> > > > > Does it work without recursive=1? (My guess is the problem is to do
> > > > > with the Author table and your model definition)
>
> > > > > FYI, the htmlhelper::tableCells & tableHeaders functions are nice for
> > > > > generating tables. :)
>
> > > > > I believe also that the preferred way in cakephp 1.2 to optimize
> > > > > database calls is to use containable behavior. ie.
> > > > > replace
> > > > > $this->Book->recursive = 1;
> > > > > with
> > > > > $this->Book->contain('Author');
>
> > > > >http://cakebaker.42dh.com/2008/05/18/new-core-behavior-containable/
>
> > > > > But try getting it to work first without optimization.
>
> > > > > On Oct 3, 1:14 am, "S/*\\L/*\\L/*\\M" <abdusal...@gmail.com> wrote:
> > > > > > hi all,
> > > > > > i m very new in cakePHP, pls help me some one about this error, which
> > > > > > is headeach for me.
> > > > > > => i m getting error of [Undefined index] in abc view file.i m
> > > > > > pasting code here if some 1 got it then pls help me.
> > > > > > thanx
>
> > > > > > =>this controller file code for index...
> > > > > > function index() {
> > > > > > $this->Book->recursive = 1;
> > > > > > $books = $this->Book->find('all');
> > > > > > $this->set('books', $books);
>
> > > > > > }
>
> > > > > > =>and this one code for index.ctp
> > > > > > <?php foreach($books as $book): ?>
> > > > > > <tr>
> > > > > > <td><?php echo $book['Book']['isbn']; ?></td>
> > > > > > <td><?php echo $book['Book']['title']; ?></td>
> > > > > > <td><?php echo $book['Author']['name'] ;?></td>
> > > > > > </tr>
> > > > > > <?php endforeach; ?>
> > > > > > ....i am waiting :)
>
> > > > --
> > > > Best Regards
> > > > ABDUS SALAAM
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment