Using Model in Component or other class in CakePHP 1.3

Some posts mentioned using

App::import('User');
$user = new User();

The issue with this approche is when you access the database, it uses default configuration. There is no problem until you are testing the class with a test database configuration or asking CakePHP to generate the test_suite configuration.

The correct way of doing this is:
$modelName = ClassRegistry::init('ModelName');

Leave a Reply

Your email address will not be published. Required fields are marked *