Temat: Nie mogę edytować rekordów
witam,
mam dziwny problem ponieważ nie mogę edytować rekordu. Zamiast edycji, wstawia nowy, oparty na starym.
tak wyglada moj model
<?php
class Product extends AppModel {
var $name = 'Product';
var $validate = array(
'name' => array('notempty'),
'status' => array('numeric'),
);
var $order = array('Product.name ASC');
var $actsAs = array('Sluggable'=>array('label'=>'name','separator'=>'-','translation'=>'utf-8'),'Translate'=>array('name','description'));
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $hasMany = array(
'Ad' => array(
'className' => 'Ad',
'foreignKey' => 'product_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Fact' => array(
'className' => 'Fact',
'foreignKey' => 'product_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Question' => array(
'className' => 'Question',
'foreignKey' => 'product_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Science' => array(
'className' => 'Science',
'foreignKey' => 'product_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Testimonial' => array(
'className' => 'Testimonial',
'foreignKey' => 'product_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
var $hasAndBelongsToMany = array(
'Category' => array(
'className' => 'Category',
'joinTable' => 'categories_products',
'foreignKey' => 'product_id',
'associationForeignKey' => 'category_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
),
'Clip' => array(
'className' => 'Clip',
'joinTable' => 'clips_products',
'foreignKey' => 'product_id',
'associationForeignKey' => 'clip_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
}
?>kontroler:
<?php
class ProductsController extends AppController {
var $name = 'Products';
var $helpers = array('Html', 'Form');
function index() {
$this->Product->recursive = 0;
$this->set('products', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Product.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('product', $this->Product->read(null, $id));
}
function admin_index() {
$this->Product->recursive = 0;
$this->set('products', $this->paginate());
}
function admin_view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Product.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('product', $this->Product->read(null, $id));
}
function admin_add() {
if (!empty($this->data)) {
$this->Product->create();
if ($this->Product->save($this->data)) {
$this->Session->setFlash(__('The Product has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Product could not be saved. Please, try again.', true));
}
}
$clips = $this->Product->Clip->find('list');
$this->set(compact('clips'));
}
function admin_edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Product', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->Product->saveAll($this->data)) {
$this->Session->setFlash(__('The Product has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Product could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Product->read(null, $id);
}
$clips = $this->Product->Clip->find('list');
$this->set(compact('clips'));
}
function admin_delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for Product', true));
$this->redirect(array('action'=>'index'));
}
if ($this->Product->del($id)) {
$this->Session->setFlash(__('Product deleted', true));
$this->redirect(array('action'=>'index'));
}
}
}
?>no i widok
<div class="products form">
<?php echo $form->create('Product');?>
<fieldset>
<legend><?php __('Edit Product');?></legend>
<?php
echo $form->input('name');
echo $form->input('description');
echo $form->input('images');
echo $form->input('flash');
echo $form->input('status');
echo $form->input('slug');
echo $form->input('date');
echo $form->input('Clip');
echo $form->input('Category');
?>
</fieldset>
<?php echo $form->end('Submit');?>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('Delete', true), array('action' => 'delete', $form->value('Product.id')), null, sprintf(__('Are you sure you want to delete # %s?', true), $form->value('Product.id'))); ?></li>
<li><?php echo $html->link(__('List Products', true), array('action' => 'index'));?></li>
</ul>
</div>czyli kod wyglada zupełnie standardowo, jednak w rekord nie jest aktualizowany tylko dodawany nowy. Czy ktoś ma jakis pomysł?
pozdr.
Ostatnio edytowany przez gaw (2009-08-25 14:39:35)