I have a plugin with a model called profile. Also I have a profile model in app/model folder, which contains a function getProfileDetails. This function I am calling from the AppController, using the following code
function beforeRender(){if ($this->isAuthorized())
{
$this->loadModel('Profile');
$this->set('ownProfile', $this->Profile->getProfileDetails($this->Auth->user('id')));
}
}
Whenver I access the plugin through the url, Im getting getting the following error
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 ‘getProfileDetails’ at line 1
/lib/Cake/Model/Datasource/DboSource.php(436): PDOStatement->execute(Array)
/lib/Cake/Model/Datasource/DboSource.php(403): DboSource->_execute(‘getProfileDetai…’, Array)
If I give the same function in Plugin/model/profile, everything is working. How to tell cake to take the App/model/profile model in loadmodel ?
Cake 2.0 and previous versions do not support duplicate Model/Controller names. The fact that such a setup was working in 1.3 and lower was an unintended side-effect unknown to the developers. Cake loads all the classes, from plugins and the actual application. So a duplicate classname anywhere in you application is bound to mess things up.
Support for duplicate classnames will likely be added in Cake 3.0 as this version willy rely on PHP 5.3 which, in turn, has support for namespaces needed to implement the ability to create duplicate classnames.
The only workaround I know of is renaming your plugin’s controllers, models and views, by prefixing the plugin name to the files and classnames, for example. If the plugin uses the same database tables as the application you’ll have to use the
$useTablemodel attribute to point the renamed models to the right database tables.Some background is covered in this bug report.