Category: Cake PHP

  • File upload

    To work on file upload we are going to use the form helper. Here, is an example for file upload. Example Make Changes in the config/routes.php file, as shown in the following program. config/routes.php Create a FilesController.php file at src/Controller/FilesController.php. Copy the following code in the controller file. Ignore, if already created. Create uploads/ directory in src/. The files…

  • Date and Time

    To work with date and time in cakephp4, we are going to make use of the available FrozenTime class. To work with date and time, include the class in your controller Let us work, on an example and display date and time, using FrozenTime class. Example Make Changes in the config/routes.php file as shown in…

  • Pagination

    If we want to show a set of data that is huge, we can use pagination and this feature is available with cake php 4 which is very easy to use. We have a table titled “articles” with following data − Let us use pagination to display the data in the form of pages, instead…

  • Creating Validators

    Validator can be created by adding the following two lines in the controller. Validating Data Once, we have created validator, we can use the validator object to validate data. The following code explains, how we can validate data for login webpage. Using the $validator object, we have first called the notEmpty() method, which will ensure that the…

  • Validation

    Often while making websites, we need to validate certain things before processing data further. CakePHP provides validation package, to build validators that can validate data with ease. Validation Methods CakePHP provides various validation methods in the Validation Class. Some of the most popular of them are listed below. Syntax Add(string $field, array|string $name, array|Cake\Validation\ValidationRule $rule…

  • Security

    Security is another important feature while building web applications. It assures the users of the website that, their data is secured. CakePHP provides some tools to secure your application. Encryption and Decryption Security library in CakePHP provides methods, by which we can encrypt and decrypt data. Following are the two methods, which are used for…

  • Cookie Management

    Handling Cookie with CakePHP is easy and secure. There is a CookieComponent class which is used for managing Cookie. The class provides several methods for working with Cookies. To work with cookies, add this 2 classes to your controller − The cookie object has to be created first to register a cookie. The name and…

  • Session Management

    Session allows us to manage unique users across requests, and stores data for specific users. Session data can be accessible anywhere, anyplace, where you have access to request object, i.e., sessions are accessible from controllers, views, helpers, cells, and components. Accessing Session Object Session object can be created by executing the following code. Writing Session…

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