Tuesday, July 21, 2020
How to create Model in CakePHP 4?
Monday, July 20, 2020
How to create controller in CakePHP 4?
Saturday, July 18, 2020
How to setup Database for CakePHP 4 Application?
Thursday, July 16, 2020
What is CakePHP 4 Development Strategy?
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.
Wednesday, July 15, 2020
What is the Design Pattern of CakePHP 4?
CakePHP 4.0 follows the MVC (Model-View-Controller) design pattern. MVC consist on three main components. Model, View and Controller

Model
Any application which is dynamic in nature depend on data, model
is the container of data. For example, Student
is a model, it contains its related data like First Name, Last Name, Roll
Number and Grade. In programming languages data is encapsulated in the objects
of as class. Model has a central role in MVC design pattern, whole application
revolves around the model. It is used to temporary store data, validate data, and
facilitate to permanently store the data in databases. In CakePHP 4.0 model is
fat layer as compare to two other components.
View
View is a perspective of viewing the data graphically, it retrieves
the data from model and represents on the page in HTML. For example Student may
have different perspectives like its Personal Information, Its Educational
Record, or its extra curriculum achievements. Each of these groups of
information is handled through models and represented on screen either in tabular
format or in any other graphical format like bar charts pie charts etc.
Controller
Controller is the middle layer between model and views, main
objective of controller is to receive the request, arrange the data through models
and handover to views for display and vice versa. In CakePHP controllers are slim
layer.
Today we have seen the design pattern of CakePHP 4.0. It is
important to understand the concept of MVC, because whole development of
application is dependent of these three types of components. In the next
article we will see the whole concept in action through the code.
Tuesday, July 14, 2020
How to Interact with MySQL?
Let’s start phpMyAdmin, go to your windows start menu and start the XAMPP control panel. Start the Apache service and MySQL service. When both services are up and running, jump to web browser and type “localhost/phpMyAdmin”. It will start the application and you will see the page like below.
Create New User in MYSQL
Click on the “User Accounts” menu on the menu bar as shown in the image.
Click on “Add User Account”.
On the Login information form enter the login information in “User Name” and in “Password” text boxes, type the same password again in the “Re-Type” text box.
Click on the “Go” button given on the extreme right bottom of the page. If not visible scroll down the page.
At this stage a new database user is created. Till now we have not assigned any privileges to this user. We will do this later in the article.
Create New Database
Click on the “Databases” menu.
Enter the database name in the text box, as I entered “MySchool”, you can enter name of your database.
Next click on the “Create” button. It will create the new database and will lead you to new page for New Table creation.
Create a New Table in Database
1) Enter the table name “Students” in the name field. You can enter your table name. in the number of column text box enter the count of your table columns in my case I have entered 3.
Click on the “Go” button, on right side of the page.
On the next page fill the data as shown in the below image.
Click on the “Save” button in the right bottom of form. it will create the new table.
Assign Privileges to User
Go to “User Accounts” page.
Select the Used “DBAdmin” by checking the checkbox in my case.
Click on the “Edit Privileges” link.
Click on “Databases” tab. Select the “MySchool” database and click on “Go” button
Now the database is selected for privileges. Click on “Go” button.
At this stage we have created a new user, created a new database, created a new table and assigned the privileges to the newly created user for the newly created database.
Stay tuned with us, in the next article we will move back to CakePHP and connect our application to this database.
Monday, July 13, 2020
How to create First CakePHP 4 Application?
Saturday, July 11, 2020
How to verify the CakePHP 4 development environment?
Hi guys, those who have not gone through my last posts, where I have explained step by step how to set up the CakePHP development environment, may check this link Home.
In this post we will proceed further to verify what we have done earlier. You can proceed step by step and confirm that everything is working fine.
Check Our Web Server Apache is working fine?
Open your XAMPP control panel form start menu, once it is started click on the start button opposite to service labelled “Apache”. It will take few seconds to start, once it is Green it means it is running in the background. In case you see the below message in the message window. Follow my post How to install and configure CakePHP 4.0?
Problem detected!
Port 443 in use by ""C:\Program Files (x86)\VMware\VMware
Workstation\vmware-hostd.exe" -u
"C:\ProgramData\VMware\hostd\config.xml"" with PID 11356!
Apache WILL NOT start without the configured ports free!
You need to uninstall/disable/reconfigure the blocking application
or reconfigure Apache and the Control Panel to listen on a different port
Once you are good to go, open your web browser and type “localhost”
in the address bar. It will open the welcome screen of XAMPP dashboard.

You can check the information about installed PHP version by
clicking the PHPInfo link on the welcome screen.
Further you can verify your PHP version by typing “PHP -v”
on command prompt.

Write your First Hello World script
Guys, if you check the PHPInfo page on XAMPP dashboard,
under the Apache Environment section, you will notice that there is one environment
variable defined “DOCUMENT_ROOT” its value is “C:/xampp/htdocs” in my case,
this is the root folder. All the PHP applications are stored under this root
folder. If you want to change this location you can change it in the “httpd.conf”
file.
Let’s create a folder under this root, name it “HelloWorld”,
create a text file, with the help of any text editor and name it “index.php”. Don’t
forget its extension. Copy the below code in the file and save it.
<?php
echo "Hello World! </br>";
echo "My First PHP script";
Now move to web browser and type in the address bar “localhost/helloworld”
you will see the below result.

So you have successfully executed the your first PHP script.
In the next post we will discover it in more detail, stay with us and subscribe the blog.
How to install CakePHP 4?



Listen 80
ServerName localhost:80
Similarly you can open the “Apache httpd-ssl.conf” file and
change the port 443 to 4433 on the below mentioned locations in the file. Once
you have done these modification start the Apache service again it will start
and show green which means it is started and running successfully.
Listen 4433
<VirtualHost _default_:4433>
ServerName www.example.com:4433

Installing Composer
Now a day’s all big frameworks
and platforms are composed of several useful packages, CakePHP is a rich
framework and depends on several packages. CakePHP requires composer which is
package manager. We need this package manager to install the CakePHP. You can
download the composer latest version form the github. Download
Once the installer setup is
downloaded just double click and run the installer. Do not change any setting
on the wizard just click next, next install and finish. For your reference images are self-explanatory as below.






Up till now we have installed all
the prerequisites and done the configuration need for the application
development.
Stay with us in next post we will start the CakePHP. We will create a project and will discover how much CakePHP is sweet.
Friday, July 10, 2020
What is CakePHP 4?
- You need HTTP web server most recommended is Apache HTTP Server. It is an open source project started in April 1996. The latest version 2.4.43 of Apache HTTP Server released on 1st April, 2020. It is available for all modern OS, Windows, Linux, Mac etc.
- Minimum PHP version 7.2 but recommended is 7.4 latest.
- Minimum PHP extensions installed mbstring, intl, simplexxml and PDO.








