2
I’ve been racking my brain here for a while and I still don’t understand the mistake. I’m learning about Cakephp. I did the Regionals table MVC manually, and for the others, I used the Bake. The problem is that when I try to add a new congregation, this title error is returned. I’ve searched elsewhere, but I haven’t found a solution yet.
Controller Congregacaoscontroller.php
/**
* Components
*
* @var array
*/
public $components = array('Paginator');
/**
* index method
*
* @return void
*/
public function index() {
$this->Congregacao->recursive = 0;
$this->set('congregacaos', $this->paginate());
}
/**
* view method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function view($id = null) {
if (!$this->Congregacao->exists($id)) {
throw new NotFoundException(__('Invalid congregacao'));
}
$options = array('conditions' => array('Congregacao.' . $this->Congregacao->primaryKey => $id));
$this->set('congregacao', $this->Congregacao->find('first', $options));
}
/**
* add method
*
* @return void
*/
public function add() {
if ($this->request->is('post')) {
$this->Congregacao->create();
if ($this->Congregacao->save($this->request->data)) {
$this->Session->setFlash(__('The congregacao has been saved'), 'flash/success');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The congregacao could not be saved. Please, try again.'), 'flash/error');
}
}
$regionals = $this->Congregacao->Regional->find('list');
$this->set(compact('regionals'));
}
/**
* edit method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function edit($id = null) {
$this->Congregacao->id = $id;
if (!$this->Congregacao->exists($id)) {
throw new NotFoundException(__('Invalid congregacao'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->Congregacao->save($this->request->data)) {
$this->Session->setFlash(__('The congregacao has been saved'), 'flash/success');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The congregacao could not be saved. Please, try again.'), 'flash/error');
}
} else {
$options = array('conditions' => array('Congregacao.' . $this->Congregacao->primaryKey => $id));
$this->request->data = $this->Congregacao->find('first', $options);
}
$regionals = $this->Congregacao->Regional->find('list');
$this->set(compact('regionals'));
}
/**
* delete method
*
* @throws NotFoundException
* @throws MethodNotAllowedException
* @param string $id
* @return void
*/
public function delete($id = null) {
if (!$this->request->is('post')) {
throw new MethodNotAllowedException();
}
$this->Congregacao->id = $id;
if (!$this->Congregacao->exists()) {
throw new NotFoundException(__('Invalid congregacao'));
}
if ($this->Congregacao->delete()) {
$this->Session->setFlash(__('Congregacao deleted'), 'flash/success');
$this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Congregacao was not deleted'), 'flash/error');
$this->redirect(array('action' => 'index'));
}
}
Model Congregacao.php
<?php
App::uses('AppModel', 'Model');
/**
* Congregacao Model
*
* @property Regionals $Regionals
* @property Membro $Membro
*/
class Congregacao extends AppModel {
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'nome' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'regionals_id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Regionals' => array(
'className' => 'Regionals',
'foreignKey' => 'regionals_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
/**
* hasMany associations
*
* @var array
*/
public $hasMany = array(
'Membro' => array(
'className' => 'Membro',
'foreignKey' => 'congregacao_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
}
Model Regional.php
public $validate = array(
'descricaoRegional' => array(
'rule' => 'notEmpty'
)
);
}
Controller Regionalscontroller.php
public function index()
{
$this->set('regionals', $this->Regional->find('all'));
}
public function view($id = null)
{
$this->Regional->regionals_id = $id;
$this->set('regional', $this->regional->read());
}
public function add()
{
if ($this->request->is('post'))
{
if ($this->Regional->save($this->request->data))
{
//$this->Session->setFlash("A regional foi adicionada com sucesso");
$this->Session->setFlash(__("A regional foi adicionada com sucesso."), 'flash_success');
$this->redirect(array('action' => 'index'));
}
}
}
public function edit($id = null)
{
$this->Regional->id = $id;
if ($this->request->is('get'))
{
$this->request->data = $this->Regional->read();
}
else
{
if ($this->Regional->save($this->request->data))
{
//$this->Session->setFlash("A regional $id foi atualizada.");
$this->Session->setFlash(__("A regional $id foi atualizada."), 'flash_success');
$this->redirect(array('action' => 'index'));
}
}
}
public function delete($regionals_id)
{
if (!$this->request->is('post'))
{
throw new MethodNotAllowedException();
}
if ($this->Regional->delete($regionals_id))
{
//$this->Session->setFlash("A regional $regionals_id foi deletada.");
$this->Session->setFlash(__("A regional $regionals_id foi deletada."), 'flash_danger');
$this->redirect(array('action' => 'index'));
}
}
}
Grateful for any help.
Xdebug is already enabled here. This "Call to a Member..." message is a ready exception to Cakephp. He even has a debug of his own, but I don’t know how to use it correctly. What else can I post to detail the error?
– Keoma Borges