I'm new to cakePHP and i have looked everywhere for an answer, but couldn't find the reason for this. I'm trying to call a function in distant model, if i run the model directly, it works fine, but if i run it from another model, it cause 'Syntax error or access violation' error.
Here's the code:
Cpanel Controller
class CpanelController extends AppController {
var $uses = array('Client');
public function index() {
$this->Client->index();
}
}
Client Model
class Client extends AppModel {
public $useTable = 'users';
}
Client Controller
class ClientController extends AppController {
public function index() {
echo "running";
}
}
When i run it from mysite/Client , it runs just fine. But if i try to load it from mysite/Cpanel , it throws:
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 'index' at line 1
Thank you,
You dont' have a index
function in your User
Model.
maybe you what you intended to do was
public function index() {
$this->Client->find('all');
}
otherwise you have to create a index function inside the model
class Client extends AppModel {
public $useTable = 'users';
public function index() {
// Do Something;
}
}
If you want to use UserController inside CpanelController here's the code
App::uses('UserController', 'Controller');
$UserController= ClassRegistry::init('UserController');
$UserController->index();