| |
ArqHP - Arquitetura de home pages |
Não tenho certeza mais acho que no cake ele faz o seguinte:
Se na hora de chamar o save existir o id, ele faz update em vez de salvar,
2008/9/23 João Vagner <joao.vag...@gmail.com>
> Estou fazendo uma galeria com o cake, e o que me ocorre é o seguinte,
> function admin_edit($id = null) {
> }
> if (!empty($this->data)) {
> }
> if (empty($this->data)) {
> $categories = $this->Gallery->Category->find('list',array('fields'=>array(
> }
> Abaixo o Model para ver se algo esta errado com ele, pois verifiquei e não
> <?php
> //The Associations below have been created with all possible keys, those
> var $belongsTo = array(
> 'User' => array('className' => 'User',
> 'foreignKey' => 'user_id',
> 'conditions' => '',
> 'fields' => '',
> 'order' => ''
> )
> );
> var $hasAndBelongsToMany = array(
> 'Category' => array('className' => 'Category',
> 'joinTable' => 'categories_galleries',
> 'foreignKey' => 'gallery_id',
> 'associationForeignKey' => 'category_id',
> 'unique' => true,
> 'conditions' => '',
> 'fields' => '',
> 'order' => '',
> 'limit' => '',
> 'offset' => '',
> 'finderQuery' => '',
> 'deleteQuery' => '',
> 'insertQuery' => ''
> ),
> 'Package' => array('className' => 'Package',
> 'joinTable' => 'galleries_packages',
> 'foreignKey' => 'gallery_id',
> 'associationForeignKey' => 'package_id',
> 'unique' => true,
> 'conditions' => '',
> 'fields' => '',
> 'order' => '',
> 'limit' => '',
> 'offset' => '',
> 'finderQuery' => '',
> 'deleteQuery' => '',
> 'insertQuery' => ''
> )
> );
> }
> ?>
> João Vagner
> 011 8923-9648
se não existir o id então ele sabe que é para criar um novo registro.
> quando vou editar uma galeria, ao clicar em update, ele me faz um insert ao
> invez do update, olhem o action dentro do controller
> galleries_controller.php
> $this->layout='admin';
> if (!$id && empty($this->data)) {
> $this->Session->setFlash(__('Invalid Gallery', true));
> $this->redirect(array('action'=>'index'));
> if ($this->Gallery->save($this->data)) {
> $this->Session->setFlash(__('The Gallery has been saved', true));
> $this->redirect(array('action'=>'index'));
> } else {
> $this->Session->setFlash(__('The Gallery could not be saved. Please, try
> again.', true));
> }
> $this->data = $this->Gallery->read(null, $id);
> }
> 'Category.id', 'Category.titulo'), 'value'=>'Category.id'));
> $packages = $this->Package->find('list', array('fields'=>array(
> 'Package.id', 'Package.titulo'), 'value'=>'Package.id'));
> $this->set(compact('categories', 'packages'));
> encontrei o motivo:
> class Gallery extends AppModel {
> var $name = 'Gallery';
> that are not needed can be removed
> j...@iw2.com.br
> www.iw2servers.com.br
> #IW² blog [ http://iw2servers.com.br/blog ]
-----------------------------------------
Danillo César de O. Melo
www.sook.com.br