Hi guys, in the last article we have discussed
the design pattern of CakePHP 4.0, today we will discuss the development
strategy. When we talk about strategy, first question comes in the mind from
where we should start. So the answer is in CakePHP we should start from the
root. The best practice is to build your database first and then application,
in CakePHP 4.0 you will get great advantage with database first approach. We will
see below what other features are in CakePHP 4.0 to make our development fast.
If you have not seen the early articles related
with CakePHP4.0 visit the main page here.
CakePHP is based on PHP scripting language,
means you have a lot of coding power, but the main advantage of CakePHP is, the
MVC design pattern and it has ORM (Object Relational Mapping) as a default
feature.
CakePHP ORM (Object Relational Mapping)
To make effective use of ORM, the most
important thing is to follow the CakePHP conventions. For more detail on conventions
check the CakePHP
Conventions.
For example if I have to retrieve all the records
from my Student Table, I will write the simple code as below.
Use Cake\ORM\TableRegistry
$students = TableRegistry::getTableLocator()->get(‘Students’);
$query = $students->find();
foreach ($query as $row) {
$row->firstname;
}
Here you have seen that I have not wrote any
SQL query, and I have retrieved the data rows form the student table. In fact
SQL query is issued but all the job is handled by the ORM behind the scene.
Bake Console is another amazing plugin available in CakePHP 4.0
Bake Console
It is a rapid development console based tool. It helps you to build fully functional application within minutes following the previously explained two concepts MVC and ORM. Before you use this tool you have to install it with the help of Composer from the command prompt. You have to type the following command in the root of your application.
Once you have installed CakePHP Bake, navigate
to your application BIN folder and type the below command to check the
available options with Bake Utility.
Using the Bake utility you can create Model, Controllers, View and many more components just with a single console command. If proper conventions are followed then this auto generated code is not an empty template but it is a fully functional code. Either you have to tweak as little or none.
Today we learned about some more helpful things
which will help us to develop the application faster. In the next article we
will use the Bake Utility and build a simple running application.
Stay tuned with us and subscribe our blog.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.