Thursday, March 3, 2011

Help with a naive delete problem

Hello

I'm just a beginner with CakePHP and I just made a model, a controller
and I try to figure out the functionality.
(see below the model and the controller)

The problem I have is that when I push the button for delete a record
the system ask if I like to delete the record #3. I say yes and an
error happens
The stack is:
Debugger::handleError() - CORE/cake/libs/debugger.php, line 306
DboSource::showQuery() - CORE/cake/libs/model/datasources/
dbo_source.php, line 684
DboSource::execute() - CORE/cake/libs/model/datasources/
dbo_source.php, line 266
DboSource::fetchAll() - CORE/cake/libs/model/datasources/
dbo_source.php, line 410
DboSource::query() - CORE/cake/libs/model/datasources/dbo_source.php,
line 364
Model::call__() - CORE/cake/libs/model/model.php, line 502
Overloadable::__call() - CORE/cake/libs/overloadable_php5.php, line 50
Seccion::del() - [internal], line ??
SeccionsController::delete() - APP/controllers/
seccions_controller.php, line 55
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171
[main] - APP/webroot/index.php, line 83

And the SQL is 'del'. This is surprising me

Could you provide to me with some hits about where my mistake is ?

Thanks in advance and sorry for disturb. I was having a look on
different websites but finally i have no real ideas.

=== Model ===
<?php
class Seccion extends AppModel {

var $name = 'Seccion';
var $validate = array(
'seccion' => array('notempty')
);

//The Associations below have been created with all possible keys,
those
that are not needed can be removed
var $hasMany = array(
'Medida' => array(
'className' => 'Medida',
'foreignKey' => 'seccion_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);

}
?>

===== Controller ========
<?php
class SeccionsController extends AppController {

var $name = 'Seccions';
var $helpers = array('Html', 'Form');

function index() {
$this->Seccion->recursive = 0;
$this->set('seccions', $this->paginate());
}

function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Seccion.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('seccion', $this->Seccion->read(null, $id));
}

function add() {
if (!empty($this->data)) {
$this->Seccion->create();
if ($this->Seccion->save($this->data)) {

$this->Session->setFlash(__('The Seccion has bee
n saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Seccion could n
ot be saved. Please, try again.', true));
}
}
}

function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Seccion', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->Seccion->save($this->data)) {
$this->Session->setFlash(__('The Seccion has bee
n saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Seccion could n
ot be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Seccion->read(null, $id);
}
}

function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for Seccion', tr
ue));
$this->redirect(array('action'=>'index'));
}
if ($this->Seccion->del($id)) {
$this->Session->setFlash(__('Seccion deleted', true));
$this->redirect(array('action'=>'index'));
}
}

}
?>

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

No comments: