Category: Cake PHP
-
Logging
Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provided by the LogTrait, which is the common ancestor for almost all CakePHP…
-
Errors & Exception Handling
Failure of system needs to be handled effectively for smooth running of the system. CakePHP comes with default error trapping, that prints and logs error as they occur. This same error handler is used to catch Exceptions. Error handler displays errors, when debug is true and logs error, when debug is false. CakePHP has number of…
-
Services
This chapter deals with the information about the authentication process available in CakePHP. Authentication Authentication is the process of identifying the correct user. CakePHP supports three types of authentication. Example for FormAuthentication Make changes in the config/routes.php file as shown in the following code. config/routes.php Change the code of AppController.php file as shown in the…
-
Delete a Record
To delete a record in database, we first need to get hold of a table using the TableRegistry class. We can fetch the instance out of registry using the get() method. The get() method will take the name of the database table as an argument. Now, this new instance is used to get particular record that we want to…
-
Update a Record
To update a record in database, we first need to get hold of a table using TableRegistry class. We can fetch the instance out of registry using the get() method. The get() method will take the name of the database table as an argument. Now, this new instance is used to get particular record that we want to update. Call the get() method…
-
View a Record
To view records of database, we first need to get hold of a table using the TableRegistry class. We can fetch the instance out of registry using get() method. The get() method will take the name of the database table as argument. Now, this new instance is used to find records from database using find() method. This method will return all…
-
Working with Database
Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter. Further, we also need to configure our database in config/app_local.php file. The default connection has following details − You can change the details, i.e. host, username, password and database as per your choice. Once done,…
-
View Events
There are several callbacks/events that we can use with View Events. These events are helpful to perform several tasks before something happens or after something happens. The following is a list of callbacks that can be used with CakePHP − Sr.No Event Function & Description 1 Helper::beforeRender(Event $event,$viewFile)The beforeRender method is called after the controller’s beforeRender method…
-
View Elements
Certain parts of the web pages are repeated on multiple web pages, but at different locations. CakePHP can help us reuse these repeated parts. These reusable parts are called Elements – help box, extra menu, etc. An element is basically a mini-view. We can also pass variables in elements. There are three arguments to the above function as…
-
Extending Views
Many times, while making web pages, we want to repeat certain part of pages in other pages. CakePHP has such facility by which one can extend view in another view and for this, we need not repeat the code again. The extend() method is used to extend views in View file. This method takes one argument, i.e., the name…