The software comes with features such as code generation and scaffolding, which allow developers to build prototypes of websites quickly without having to worry about complicated XML or YAML files. Cake PHP has become a useful technology for almost everyone regardless if they are developers or no. If you want to get on the delicious CakePHP training, it is not yet too late. Here are a few resources that you can use to start learning CakePHP.
The following resources contain additional information on CakePHP. Please use them to get more in-depth knowledge on this.
Form is a simple input taker in applications, defined inputs by users need authentication and formatting to be stored. Cakephp makes easy FormHelper to work with form. It is quick and will streamline validation, re-population and layout.
CakePHP – 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.
The model name for which the form is being defined. Should include the plugin name for plugin models. e.g. ContactManager.Contact. If an array is passed and $options argument is empty, the array will be used as options. If false no model is used.
An array of html attributes and options. Possible options are type, action, url, default, onsubmit, inputDefaults, encoding
Returns
A formatted opening FORM tag.
Description
Returns an HTML FORM element.
The following functions are used to provide file uploading functionality on HTML page.
Syntax
file(string $fieldName, array $options array() )
Parameters
Name of a field, in the form “Modelname.fieldname”
Array of HTML attributes.
Returns
A generated file input.
Description
Creates file input widget.
The following functions are used to create hidden element on HTML page.
The label appearing on the button OR if string contains :// or the extension .jpg, .jpe, .jpeg, .gif, .png use an image if the extension exists, AND the first character is /, image is relative to webroot, OR if the first character is not /, image is relative to webroot/img.
Array of options. Possible options are div, before, after, type etc.
Returns
An HTML submit button
Description
Creates a submit button element. This method will generate <input/> elements that can be used to submit, and reset forms by using $options. Image submits can be created by supplying an image path for $caption.
The following functions are used to generate textarea element on HTML page.
Name of a field, in the form “Modelname.fieldname”
Array of HTML attributes, special option like escape
Returns
A generated HTML text input element
Description
Creates a textarea widget
Example
Make changes in the config/routes.php file as shown in the following code.
config/routes.php
<?php use CakeCorePlugin; use CakeRoutingRouteBuilder; use CakeRoutingRouter; Router::defaultRouteClass(‘DashedRoute’); Router::scope(‘/’, function (RouteBuilder $routes) { $routes->connect(‘register’,[‘controller’=>’Registrations’,’action’=>’index’]); $routes->fallbacks(‘DashedRoute’); }); Plugin::routes();
Create a RegistrationController.php file at src/Controller/RegistrationController.php. Copy the following code in the controller file.
src/Controller/RegistrationController.php
<?php namespace AppController; use AppControllerAppController; class RegistrationsController extends AppController{ public function index(){ $country = array(‘India’,’United State of America’,’United Kingdom’); $this->set(‘country’,$country); $gender = array(‘Male’,’Female’); $this->set(‘gender’,$gender); } } ?>
Create a directory Registrations at src/Template and under that directory create a View file called index.ctp. Copy the following code in that file.