Alas. nothing change, valid author_id valid is inside array.

On 4 Ago, 20:58, cricket <zijn.digi...@gmail.com> wrote:
> On Wed, Aug 4, 2010 at 6:05 AM, Mariano C. <mariano.calan...@gmail.com> wrote:
> > I know, this is a stupid question but I don't know how resolve this, I
> > have read a lot of docs but still don't understand.
>
> > I'm trying to create a biblio service and map Books/Authors,
> > I have SQL table for authors:
>
> > CREATE TABLE `authors` (
> > `id` int( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
> > `name` varchar( 127 ) NOT NULL ,
> > `email` varchar( 127 ) NOT NULL ,
> > `website` varchar( 127 ) NOT NULL
> > );
>
> > and related model
> > <?php
> > class Author extends AppModel
> > {
> > var $name = 'Author';
> > var $hasMany = 'Book';
> > }
> > ?>
>
> > and table for Books (with foreing key for author):
> > CREATE TABLE `books` (
> > `id` int( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
> > `isbn` varchar( 13 ) NOT NULL ,
> > `title` varchar( 64 ) NOT NULL ,
> > `description` text NOT NULL ,
> > `author_id` int( 11 ) NOT NULL
> > )
>
> > and related model:
> > <?php
> > class Book extends AppModel
> > { var $name = 'Book';
> > var $belongsTo = 'Author';
> > }
> > ?>
>
> > It seems all ok, now I try to insert new book in DB (author will be
> > choose by a select form).
> > <?php
> > class BooksController extends AppController {
> >  var $name = 'Books';
> >  function add() {
> >     if (!empty($this->data)) {
> >        $this->Book->save($this->data);
> >     }
> >    $authors = $this->Book->Author->find('list');
> >    $this->set('authors', $authors);
> >   }
> > }
> > ?>
>
> > and add view:
> > <?php echo $form->create('Book');?>
> > <fieldset>
> > <legend>Add New Book</legend>
> > <?php
> > echo $form->input('isbn');
> > echo $form->input('title');
> > echo $form->input('description');
> > echo $form->input('author_id');
> > ?>
> > </fieldset>
> > <?php echo $form->end('Submit');?>
>
> echo $form->input('author_id', array('options' => $authors));

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to