Home » Interview Question » Cake Php » cakephp interview questions and answers

cakephp interview questions and answers

cakephp interview questions and answers

Question :How to write the session in cakephp.
Ans : To write the values in session we use Session components.We can call session components globally in App controller or can be call on your current user controller.
Call the Session component
public $components = array(‘Session’);
$this->Session->write(‘userName’,$this->request->data[‘User’][‘name’]);

Question : How to Read the session all variables.
Ans : We use read() function from Session components to read the data from session
$session = $this->Session->read();

Question : How to read the specific variables from session.
Ans :
$role_id=$this->Session->read(‘Auth.User.role_id’);

Question : How to Delete the specific variables from session.
Ans :
$this->Session->delete(‘User.auth’);

Question : How to set the defaut time zone in php .
Ans : We use date_default_timezone_set function to set the time zone in your cakephp application.
Open core config file in your editor and set your time zone.
D:\xamp\htdocs\YourProject\app\Config\core.php
date_default_timezone_set(‘UTC’);

To get the set timezone we used date_default_timezone_get function in cakephp
date_default_timezone_get()

Question : How we use Auth components in over application for perticular action.
Ans : Set action name in below auth allow action in beforeFilter action in controller
$this->Auth->allow(‘forgot’,’fpassword’);

Question : How to Use Paginator components in cakephp.
Ans :
Define components in your controller class
public $helpers=array(‘Html’);
public $components = array(‘Paginator’);

Question : Create a log in controller class.
Ans : Write below line in your controller action which is log controller and action name in log
$this->log($this->params->controller . ” ” . $this->params->action . ” entered here”);

Question : How to get the Post Data in cakephp.
Ans : using cake php is method
$this->request->is(‘post’);

Question : How TO wirte the custome query in controller action.
Ans : $this->ModelName->query we can write custome query in CakePhp
$menu = $this->ModelName->query(‘select Menu.* from module_masters Menu,role_module_permissions rm where Menu.id=rm.module_id and role_id=’.$role_id.';’);

Question : How to retrieve the data from another model in your controller.
Ans : Get different models data in controller

First load model in the controller class by variable $uses

var $uses = array(‘Post’);

or in action use method

$this->loadModel(‘Post’);

, , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">