Wednesday, August 1, 2012

Re: Getting DB error on calling Model

Thanks for the help, but it hasn't made any difference.  I'm totally baffled, because I've used the same code in other places with different model names, and it seems fine... I must have just missed something on copying it.



On Wednesday, 1 August 2012 20:58:42 UTC+1, majna wrote:
Model Confcommittee is not found, so Cake creates an instance of AppModel.
You are using $uses property, so try to add in Model/Confcommittee.php:

App::uses('Confcommittee ', 'Model');

class Confcommittee extends AppModel { ...

Btw, you don't need to call exit() after redirect() in that controller.


On Wednesday, August 1, 2012 5:44:18 PM UTC+2, WhyNotSmile wrote:
I'm using Cake 2.0, and getting a database error when I call a particular model.  I think I've probably named something wrongly, but I can't see what!

I have the following:

DB table: confcommittees

Model/Confcommittee.php:
class Confcommittee extends AppModel {
    public $name = 'Confcommittee';

    var $belongsTo = array('Conference');

    public function myFunction() {
        return false;
    }
}

Controller/ConferencesController.php:
App::uses('AppController', 'Controller');
class ConferencesController extends AppController {
public $name = 'Conferences';
public $helpers = array('Html', 'Session');
public $uses = array('Conference', 'Confcommittee');

/* Filters and callbacks */
function beforeFilter() {
parent::beforeFilter();
}
/*
* admin_manage
* Allows the admin user to manage any given conference
*/
function admin_manage($conference_id = null) {
if(!$conference_id) {
$this->redirect('/admin/conferences/main');
exit;
}
$this->Confcommittee->myFunction();
        }
}
When I access admin/conferences/manage, I get the following error:
Database Error
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'myFunction' at line 1
SQL Query: myFunction
Notice: If you want to customize this error message, create app\View\Errors\pdo_error.ctp
Stack Trace

As I said, I think I've given something the wrong name, but I can't find it.  Can anyone help?! 

--
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: