CakePHP Interview Questions and Answers
CakePHP is a modern, open-source PHP 7 framework that makes building web applications simpler and faster. It is based on MVC architecture that is powerful and quick to grasp. The in-built models, controllers, and views allow natural separation of logic from presentation layers. This framework requires less code and offers a flexible database access layer with a powerful scaffolding system. A lot of CakePHP interview questions were asked about the basic overview.
Advantages
- Build apps quickly
- Complicated XML and YAML files not required.
- Ideal for making commercial apps.
- Secure, scalable and stable
- Unique built-in features like translation, caching, database access, and authentication.
Here are some of the CakePHP Interview Questions for freshers as well as experienced candidates:
Development History
Michal Tatarynowicz, a Polish programmer, started CakePHP in April 2005. The framework got published under the MIT license. L. Masters and G. J. Woodworth founded the Cake Software Foundation in Dec 2005 to promote the development of CakePHP and released Version 1.0 in May 2006.
Latest Version: Version CakePHP 3.7.2 got released in Jan 2019.
Top CakePHP Interview Questions
CakePHP is a modern, open-source PHP 7 framework that makes building web applications simpler and faster. It is based on MVC architecture that is powerful and quick to grasp. It is used to develop web applications.
- Build apps quickly
- Complicated XML and YAML files not required.
- Ideal for making commercial apps.
- Secure, scalable and stable
- Unique built-in features like translation, caching, database access, and authentication.
CakePHP 3.7.2
Composer is a tool used for project dependencies.
To install cakePHP we can use
Execute this "php composer.phar create-project –prefer-dist cakephp/app MyProject
"
CakePHP is quite simple and easy to install.
- HTTP Server should Have mod_rewrite is preferred.
- PHP 5.6.0 or greater including PHP 7.2 (PHP latest version)
- mbstring PHP extension
- intl PHP extension
- simplexml PHP extension
For more details you can visit cakePHP official website Click here
It is used for creating a variable in the view file with $this->set('variable1','bestinterviewquestion.com');
in controller fie and then that variable $variable1 will be available to use in the view template file for that action.
It allows us to manage unique users across requests and also helps to stores data for specific users. We can access session from controllers, views, helpers, cells, and components.
We can use session in cakePHP in following ways :-
How to create session?
We can use the write() to create or write session.
Example : $session->write('username', 'bestinterviewquestion.com');
How to read session?
We can use the read() to get stored data from session.
Example : $session->read('username');
How to Check session?
We can use the check() to check this data is exists or not in session.
Example :
if ($session->check('username')) {
// name exists and is not null.
}
How to delete session?
We can use the delete() to delete data from session.
Example : $session->delete('username');
How to destroy session?
We can use the destroy() to destroy session.
Example : $session->destroy();
1. Open your controller file & put below code.
public $paginate = [
'limit' => 10,
'order' => [
'Users.name' => 'asc'
]
];
2. After this now load Paginator in initialize (). public function initialize()
{
parent::initialize();
$this->loadComponent('Paginator');
}
3. Please set Paginate in Index function.
public function index() {
$this->layout=false;
$details=$this->Users->find('all');
$this->set('users', $this->paginate($details));
}
4. You can write this code in your "index.ctp" page.
echo $this->Paginator->prev('< ' . __('previous'), array('tag' => 'li', 'currentTag' => 'a', 'currentClass' => 'disabled'), null, array('class' => 'prev disabled'));
echo $this->Paginator->numbers(array('separator' => '','tag' => 'li', 'currentTag' => 'a', 'currentClass' => 'active'));
echo $this->Paginator->next(__('next').' >', array('tag' => 'li', 'currentTag' => 'a', 'currentClass' => 'disabled'), null, array('class' => 'next disabled'));
?>
It is the component like classes for the presentation layer of our application. Helpers contain presentational logic that is shared between any views, elements, or layouts in cakePHP.
Most common helpers used in cakePHP, is given below:-
- FormHelper
- HtmlHelper
- JsHelper
- CacheHelper
- NumberHelper
- Paginator
- RSS
- SessionHelper
- TextHelper
- TimeHelper etc
It is a class file that contains the common code and logic. It can be shared between the application's controllers. We can perform various common tasks like session handling, cookies and security related things with the help of components.
In CakePHP, we can use various components that are given below:-
- Authentication
- Cookie
- Cross-Site Request Forgery
- Flash
- Security
- Pagination
- Request Handling etc