What is CakePHP?
CakePHP is a free, open-source, rapid development framework for PHP. It’s a foundational structure for programmers to create web applications. Which uses commonly known design patterns like Active Record, Association Data Mapping, Front Controller and MVC. CakePHP primary goal is to enable you to work in a structured and rapid manner–without loss of flexibility.
Why use CakePHP?
CakePHP is a free, open source framework that offers a fast application development platform to web developers. Because the name suggests, it uses PHP, the foremost well-liked open source programing language for developing web applications. CakePHP permits web Development Company to develop extremely sturdy and featured websites by exploitation easy procedures. though there are several PHP frameworks obtainable within the market however CakePHP development services has managed to secure its position among the foremost well-liked web development platforms obtainable within the market.
The reasons to use CakePHP for web development are:
- MVC Pattern
- Object relational Mapping
- Allows the Reusability of the Code
- In-built Validation
- Zero configuration
- CRUD Scaffolding
What are the features of CakePHP?
- MVC Pattern
- ORM
- Class inheritance
- Easily extend with plug-ins
- New Methods
- Scoped and New Middleware
- Cache Engine Fallbacks
- Improved Console Environment
- Cookie Objects
- CRUD (Create, Read, Update and Delete) Scaffolding
- Built-in Validation
- Built-in dotenv Support
- Flexible ACL
- Data Sanitization
- Flexible Caching
- Compatible with versions 4 and 5 of PHP
- Localization and more
What is the naming convention in cakephp?
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,
Can you explain Routing?
Routing maps your URL to specific controller’s action. In this section, we will see how you can implement routes, how you can pass arguments from URL to controller’s action, how you can generate URLs, and how you can redirect to a specific URL. Normally, routes are implemented in file config/routes.php. Routing can be implemented in two ways:
- Static method
- Scoped route builder
What is Scaffolding in Cakephp?
Scaffolding is a technique that allows a developer to define and create a basic application that can create, retrieve, update and delete objects.
What is Redirect Routing?
Redirect routing is useful when we want to inform client applications that this URL has been moved. The URL can be redirected using the following function.
Static Cake\Routing\Router::redirect($route, $url, $options =[])
There are three arguments to the above function −
- A string describing the template of the route.
- A URL to redirect to.
- An array matching the named elements in the route to regular expressions which that element should match
What is the naming convention in cakephp?
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,
Can you explain MVC in CakePHP?
CakePHP follows the MVC software design pattern. Programming using MVC separates your application into three main parts:
Model: The Model represents the application data. It is responsible for retrieving data and converting it into meaningful concepts for your application.
View: The View renders a presentation of model data. It is responsible for generating the specific output required for the request.
Controller: The Controller handles and routes requests made by the client. It provides the application’s main functionality by collecting input coordinating the model and view code.
What are the Logging levels?
Logging can also be a way to find out what’s been going on in your application over time. Logging data in CakePHP is easy – the log () function is provided by the LogTrait, which is the common ancestor for many CakePHP classes. If the context is a CakePHP class (Controller, Component, View,…), you can log your data. You can also use Log::write () directly.
CakePHP supports various logging levels as shown below;
- Emergency: System is unusable
- Alert: Action must be taken immediately
- Critical: Critical conditions
- Error: Error conditions
- Warning: Warning conditions
- Notice: Normal but significant condition
- Info: Informational messages
- Debug: Debug-level messages
Can you define layout?
Layout in cakephp are used to display the views that contain presentational code. In simple views are rendered inside a layout
What is a Helper?
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. CakePHP includes a number of helpers that aid in view creation. They assist in creating well-formed markup (including forms), aid in formatting text, times and numbers, and can even speed up AJAX functionality.
CakePHP Helpers are:
- Breadcrumbs
- Flash
- Form
- Html
- Number
- Paginator
- Rss
- Session
- Text
- Time
- Url
What is the use of Security.salt and Security.cipherSeed in cakephp? How to change its default value?
The Security.salt is used for generating hashes.we can change the default Security.salt value in /app/Config/core.php.
The Security.cipherseed is used for encrypt/decrypt strings.We can change the default Security.cipherSeed value by editing /app/Config/core.php.
What is requestAction method?
The method requestAction is used to call a controller’s action from any location and returns data from the action.
What are the name relational database servers supported CakePHP?
CakePHP supports the following relational database servers:
- MySQL 5.1+
- SQLite 3
- PostgreSQL 8.3+
- SQLServer 2008+
- Oracle (through a community plugin)
What is the name of Cakephp database configuration file name and its location?
Default file name is database.php.default.
It’s located at “/app/config/database.php.default”.To connect with database it should be renamed to database.php
Can you list some database related functions in cakephp?
find, findAll , findAllBy , findBy , findNeighbours and query.
How to get current URL in CakePHP?
To get current url in cakephp use,
echo Router::url($this->here, true);
This will give full URL with hostname.If you want to get relative path instead of full URL,then use the following code:
echo $this->here;
This will produce absolute URL excluding hostname i.e. /controller/abc/xyz/
What is a Component in cakephp?
Components are packages of logic that are shared between controllers. They are useful when a common logic or code is required between different controllers. CakePHP comes with a fantastic set of core components you can use to aid in various common tasks. You can also create your own components. Creating components keeps controller code clean and allows you to reuse code between different controllers.
What are commonly used components of cakephp?
- Authentication
- Cookie
- Flash
- Security
- Cross Site Request Forgery
- Pagination
- Request Handling
Can you define Behavior?
Behaviors in CakePHP are associated with Models. Behaviors are used to change the way models behaves and enforcing model to act as something else.
Why cakephp have two vendor folder? What is the difference between two vendors folder available in cakephp?
There will be two vendor folders available in cakephp frame work.
one in ” app ” folder and one in root folder
The vendor folder in the app folder is used to place the third-party libraries which are application specific.
The vendor folder in the root folder is used to place the third-party libraries which are used for multiple applications.
Can you define Element?
Element in cakephp are smaller and reusable bits of view code. Elements are usually rendered inside views.
How can you set custom page title for the static page?
To set a custom page title, copy-paste following code anywhere in your static page (.ctp) file:
$this->set(“title_for_layout”, “My page title”);
How to display the schema of the model?
If you want to display the schema of particular model then you just need to add the following single line of code.For example we have “Posts” Controller.
How to install CakePHP?
Go to cakephp.org and download the latest version of cakephp.
Cakephp comes in a .zip file,so unzip it.
Extract the files in the localhost in the desired folder (for example:cakephp).
Open the browser and run the URL localhost/cakephp
Just Follow the instructions display on the page.
What is Registry Objects?
The registry classes provide a simple way to create and retrieve loaded instances of a given object type. There are registry classes for Components, Helpers, Tasks, and Behaviors.
What is inflector?
The Inflector class takes a string and can manipulate it to handle word variations such as pluralizations or camelizing and is normally accessed statically. Example: Inflector::pluralize(‘example’) returns “example
What are chronos in CakePHP?
Chronos provides a zero-dependency collection of extensions to the DateTime object. In addition to convenience methods, Chronos provides:
- Date objects for representing calendar dates.
- Immutable date and datetime objects.
- A pluggable translation system. Only English translations are included in the library. However, cakephp/i18n can be used for full language support.
What is meant by Migrations?
Migrations is a plugin supported by the core team that helps you do schema changes in your database by writing PHP files that can be tracked using your version control system.It allows you to evolve your database tables over time. Instead of writing schema modifications in SQL, this plugin allows you to use an intuitive set of methods to implement your database changes.
What are the pros and cons of CakePHP?
Pros:
- Great community support which can clear any queries about website development in an effective way.
- Very useful ORM which helps developers to create excellent queries as well as codes.
- Availability of fantastic plugins to keep the codes clean as well as elegant
- CakePHP also comes with a templating system that is both fast and flexible.
- Tons of free downloadable sample code and applications.
- In comparison to other PHP frameworks, CakePHP comes with more innovative built-in tools to make the web applications safe and secure. The programmers can use the built-in tools to prevent SQL injection and cross site scripting (XSS) attacks. Also, the tools help developers to validate user input, and prevent form tampering and CSRF.
Cons:
- Bulky codes. When we compare CakePHP with other frameworks the codes for doing a particular task look huge.
- It is one of the slowest performing platforms.
- The loading of codes, even though auto loading options work in a minimum pace.
- CakePHP does not support default routes for Fancy URLs. So while crating Fancy URLs, programmers are required to update the default routes. The feature adversely affects the efficiency of CakePHP for modern web application development.
- Difficult to learn