Author: Awais Farooq

  • Internationalization

    Like many other frameworks, CakePHP also supports Internationalization. We need to follow these steps to go from single language to multiple language. Step 1 Create a separate locales directory resources\locales. Step 2 Create subdirectory for each language, under the directory src\Locale. The name of the subdirectory can be two letter ISO code of the language…

  • Form Handling

    CakePHP provides various in built tags to handle HTML forms easily and securely. Like many other PHP frameworks, major elements of HTML are also generated using CakePHP. Following are the various functions used to generate HTML elements. The following functions are used to generate select options − Syntax _selectOptions( array $elementsarray(), array $parentsarray(), boolean $showParentsnull, array $attributesarray() ) Parameters Elements to formatParents…

  • 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…