What is CakePHP?
CakePHP is a model–view–controller (MVC) based PHP web framework that provides rapid development of web applications and APIs. CakePHP is inspired by Ruby on Rails framework and distributed under the MIT License.
CakePHP is a model–view–controller (MVC) based PHP web framework that provides rapid development of web applications and APIs. CakePHP is inspired by Ruby on Rails framework and distributed under the MIT License.
Quick Questions | Answers |
CakePHP is a | MVC-based Rapid Development Framework |
CakePHP is written in | PHP (PHP: Hypertext Preprocessor) |
CakePHP is developed By | Cake Software Foundation, Inc. |
CakePHP is initially released on | April 2005 (about 17 years ago) |
CakePHP is based on | MVC Design pattern |
CakePHP dependencies | Php 5.6+, MYSQL 5.1+, PDO Driver, SimpleXML, mbstring, intl PHP extension |
CakePHP is licensed under | MIT License |
CakePHP features are | MVC architecture, Built-in ORM, Built-in validation, Built-in AJAX support |
A CakePHP developer is responsible for the development and maintenance of web applications using the CakePHP framework. Some key responsibilities of a CakePHP developer may include:
Below are the list of Best Cakephp Interview Questions and Answers
CakePHP is an open-source free web framework written in PHP scripting Language for rapid web development. CakePHP follows the model–view–controller (MVC) approach and modeled after the concepts of Ruby on Rails, and distributed under the MIT License.
In Cakephp 2.x you can get current url in view by using $this->here; or Router::url( $this->here, true );
In Cakephp 3.x you can get current url in view by using $this->Url->build(null, true);
Also, Read Best Core PHP Interview Questions
MVC stands for the model view controller.MVC is not a design pattern, it is an architectural pattern that describes a way to structure our application and explains the responsibilities and interactions of each part in that structure:
Model: Wraps up data and logic of CakePHP.
View: Handles output and presentation to User.
Controller: Manipulates the data from models and generates or pass it to views.
image Source:https://developer.chrome.com/apps/app_frameworks
CakePHP hooks are callback functions that are called before or after a model operation.We define these functions in our Model classes.
Below is the list of some hooks or callback functions provided by CakePHP.
Top features of CakePHP framework
You may also Read PHP 7 interview questions
PHP Sessions allows you to identify unique users across requests and store persistent data for specific users against a unique session ID. This can be used to persist state information between page requests. Session IDs are normally sent to the browser via session cookies and the ID is used to retrieve existing session data.
You can access the session data any place you have access to a request object. This means the session is accessible from:
In addition to the basic session object, you can also use the Cake\View\Helper\SessionHelper to interact with the session in your views. A basic example of session usage would be:
$name = $this->request->session()->read('User.name'); // If you are accessing the session multiple times, // you will probably want a local variable. $session = $this->request->session(); $name = $session->read('User.name');
Session::read($key) function is used to read specific session data in CakePHP.
Session::write($key, $value) function is used to write session data in CakePHP.
Session::delete($key) function is used to delete specific session data in CakePHP.
Sample Usage
//Reading a session $session->read('Config.language'); //Writing a session $session->write('Config.language', 'en'); //Deleting a session $session->delete('Some.value');
In CakePHP controller Pagination component is used to building paginated queries. In order to generate pagination links & buttons in view PaginatorHelper is used
Below are sample pagination usage code in CakePHP
class PostsController extends AppController { public $paginate = [ 'limit' => 25, 'order' => [ 'Posts.id' => 'desc' ] ]; public function initialize() { parent::initialize(); $this->loadComponent('Paginator'); $this->loadHelper('Paginator', ['templates' => 'MyPlugin.paginator-templates']); } public function display(){ $this->set('posts', $this->paginate()); } }
<?php $paginator = $this->Paginator; if($posts){ //creating our table echo "<table>"; // our table header, we can sort the data user the paginator sort() method! echo "<tr>"; // in the sort method, there first parameter is the same as the column name in our table // the second parameter is the header label we want to display in the view echo "<th>" . $paginator->sort('id', 'ID') . "</th>"; echo "<th>" . $paginator->sort('title', 'Title') . "</th>"; echo "<th>" . $paginator->sort('published_on', 'Published on') . "</th>"; echo "</tr>"; // loop through the user's records foreach( $posts as $post ){ echo "<tr>"; echo "<td>{$post['Post']['id']} </td>"; echo "<td>{$post['Post']['title']} </td>"; echo "<td>{$post['Post']['published_on']} </td>"; echo "</tr>"; } echo "</table>"; // pagination section echo "<div class='paging'>"; // the 'first' page button echo $paginator->first("First"); // 'prev' page button, // we can check using the paginator hasPrev() method if there's a previous page // save with the 'next' page button if($paginator->hasPrev()){ echo $paginator->prev("Prev"); } // the 'number' page buttons echo $paginator->numbers(array('modulus' => 2)); // for the 'next' button if($paginator->hasNext()){ echo $paginator->next("Next"); } // the 'last' page button echo $paginator->last("Last"); echo "</div>"; } // tell the user there's no records found else{ echo "No posts found."; } ?>
CakePHP supports Cache out of the box. Below is the list of Cache engines supported by CakePHP.
Composer is a tool for managing project dependencies. You can create a CakePHP project using Composer by running below commands on terminal.
php composer.phar create-project --prefer-dist cakephp/app my_app_name
In CakePHP, components are packages of logic that are shared between controllers. CakePHP comes with a fantastic set of core components you can use to aid in various common tasks.Using component in your application makes your controller code cleaner and allows you to reuse code between different controllers.
Below are the list some commonly used CakePHP components
In CakePHP Default controller is indexController.php and Default function is index.
There are four association supported by CakePHP they are:
Minimum server requirements to install CakePHP 3.8.5
Never Miss an Articles from us.