Thursday, 25 January 2007
Article: Creating a Model Instance Manually in CakePHP |
| |
|
| |
Felix Geisendörfer in a new post over the Thinkingphp blog shows you how to create a Model instance in CakePHP manually. He says to work on a Model outside of a Controller, a good example for this would be a smart helper that creates input fields / widgets based on the field types in the DB based on the one in Cake 1.2. He shows it with a code that is commonly used. Though the above code works but it’s not sufficient enough for better performance and error handling. So, Felix creates a function that will implement an improved performance. He passes the name of a Model, which will either return an instance of it or 'false' indicating that it's not possible to get a reference of this Model. This he explains with a long code example.
He also provides a shorter usage of the long code. He informs you that this is not an invitation to break up with the MVC pattern, but just a good approach for a complex component/helper/ and such. On questions like where to place this function, he uses a component named 'Common' for this. This allows you to make static calls like Common::getModel in your project. But AppController, or bootstrap.php should work just as well he comments. |
| |
|
Read the Article
|
| |
|
|
| |
|
|
| |
|