CakePHP is a free, open-source, rapid development framework for PHP. It's a foundational structure for programmers to create web applications. There is a number of inbuilt component like Ajax, RequestHandler, Session, etc. official website of cakephp is https://cakephp.org/
CakePHP is used for rapid development for PHP based web applications, etc.
Model View Controller (MVC) is an architectural pattern used in software engineering.
The controller receives a request from the client, invokes the model to perform the requested operations, and sends the data to the View. The view formats the data to be presented to the user, in a web application as an HTML output
There are many few key features are given below:
- MVC architecture
- Built-in validations
- Auth & ACL
- Rapid Development
- Secure, Scalable and Stable
- CSRF protection via Security Component
You can create a CakePHP project using Composer by running below commands on terminal.
Prerequisite CakePHP 3.x
- PHP 5.6.0 or greater (including PHP 7.1).
- mbstring PHP extension installed and enabled
- intl PHP extension
- simplexml PHP extension
You may also like - MongoDB Interview Questions
- CakePHP started, in April 2005.
- CakePHP version 1.0 released in May 2006.
bootstrap.php is the file that is loaded first when the application run.
You can change this if required, it can be changed either through index.php or .htaccess.
You may also like - Core PHP Interview Questions
Default controller is indexController.php and Default function is index.
- The root one is the global vendors folder - if multiple apps share the same root (cake + plugins + vendors)
- the APP one is the app specific one and takes precedence
- bin folder holds the Cake console executables.
- config folder holds the (few) Configuration files CakePHP uses. Database connection details, bootstrapping, core configuration files and more should be stored here.
- plugins folder is where the Plugins your application uses are stored.
- logs folder normally contains your log files, depending on your log configuration.
- src folder will be where you work your magic: it’s where your application’s files will be placed.
- tests folder will be where you put the test cases for your application.
- tmp folder is where CakePHP stores temporary data. The actual data it stores depends on how you have CakePHP configured, but this folder is usually used to store model descriptions and sometimes session information.
- vendor folder is where CakePHP and other application dependencies will be installed. Make a personal commitment not to edit files in this folder. We can’t help you if you’ve modified the core.
- webroot directory is the public document root of your application. It contains all the files you want to be publically reachable.
Make sure that the tmp and logs folders exist and are writable, otherwise the performance of your application will be severely impacted. In debug mode, CakePHP will warn you, if it is not the case.
CakePHP’s src folder is where you will do most of your application development.
Let’s look a little closer at the folders inside src.
- Console: Contains the console commands and console tasks for your application. For more information see Shells, Tasks & Console Tools.
- Controller: Contains your application’s controllers and their components.
- Locale: Stores string files for internationalization.
- Model: Contains your application’s tables, entities and behaviors.
- View: Presentational classes are placed here: cells, helpers, and template files.
- Template: Presentational files are placed here: elements, error pages, layouts, and view template files.
- Table names are plural and lowercased
- model names are singular and CamelCased: ModelName
- model filenames are singular and underscored: model_name.php
- controller names are plural and CamelCased with *Controller* appended: ControllerNamesController
- controller filenames are plural and underscored with *controller* appended: controller_names_controller.php
You may also like - Yii2 Interview Questions Answers
- Can be done on submission in the controller
- ACL(Access control lists)
- Request Handling
- MVC architecture
- Built-in validations
You may also like - Top 50 Laravel Interview Questions
Helpers in CakePHP are associated with Presentation layers of application. Helpers mainly contain presentational logic which is available to share between many views, elements, or layouts.
- Component is used to extend a Controller
- Behavior is used to extend a Model
- Helper is used to extend a View
- A shopping cart
Componentmight offer functionality that can be used and shared across multiple Controllers.
- A custom upload
Behaviorcould be used to extend a Model, for example to add images uploads. Another common example of a
Behaviorwould be to add extra validation functionality beyond that which CakePHP offers by default.
Helpercan be used to assist with View functionality.
The set() method is used for creating a variable in the view file.
For Example, if we write, $this->set('posts',$posts); in controller fie, then the variable $posts will be available to use in the view template file for that action.
The default extension of view files is .ctp
You may also like - MySQL Interview Questions
- The Security.salt is used for generating hashes. We can change the default Security.salt value in /app/Config/core.php
- Security.cipherseed is used for encrypt/decrypt strings. We can change the default Security.cipherSeed value by editing /app/Config/core.php.
Scaffolding is a technique that allows a developer to define and create a basic application that can create, retrieve, update and delete objects.
To add scaffolding to your application, just add the $scaffold variable in the controller.
Scaffolding is Automatic CRUD creation, but i suggest not to use it because at any stage you will need to write your own code.
- Validate the data before inserting it into the database.
- Want to do some changes after inserting them into the database.
Associations - Linking Tables Together
Associations are the terms which means getting the data from database which are in different tables.
The four association types in CakePHP are: hasOne, hasMany, belongsTo, and belongsToMany.
|one to one||hasOne||A user has one profile.|
|one to many||hasMany||A user can have multiple articles.|
|many to one||belongsTo||Many articles belong to a user.|
|many to many||belongsToMany||Tags belong to many articles.|
Associations are defined during the initialize() method of your table object.
For example if we wanted to define a belongsTo association in our ArticlesTable:
If we had the UsersTable and AddressesTable classes made we could make the association with the following code:
For more details Click to read
You may also like - RESTful Web Services Interview Questions