Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn on /off the debug mode for particular controller in cakephp

Tags:

php

cakephp

I want to turn on the debug mode for particualr controller in cakephp . Now I am doing this in config/core.php ,it working fine . But it is easy to enable /disable in controller ,we can avoid probelms with working in live sites ,otherwise the log will messed up users

like image 589
Rinto George Avatar asked Feb 27 '12 08:02

Rinto George


People also ask

How to off debug mode in php?

Enable or disable debug mode using app. Open the app. php file located in your config/app. php laravel project. Search for debug key and change true to enable debug mode and false for disabling debug mode default it will show false.


2 Answers

It work for me in cakephp 3.4.

Use the below code in top of your controller in cakephp 3+:

use Cake\Core\Configure;

Then your beforeFilter() code should be something like below:

public function beforeFilter(\Cake\Event\Event $event){
    parent::beforeFilter($event);
    $this->loadComponent('RequestHandler'); 

    // allow the function to public access
    $this->Auth->allow(['index','logout','register','saveOrders']);

    $actions = [
       'saveOrders','save-orders',
    ];

    // change the debug mode for a particular action
    if (in_array($this->request->params['action'], $actions)) {
       Configure::write('debug', false); // off debug mode
    }
}
like image 164
kantsverma Avatar answered Oct 21 '22 07:10

kantsverma


I'm late to the party on this one but just in case anyone else needs this

$skdebug = 0;
if ($_SERVER["REMOTE_ADDR"]== '121.75.33.244') $skdebug = 2;
Configure::write('debug', $skdebug);

I work offsite so I'm the only user on the IP, can be a pain to have to keep updating the IP when the router decides to bounce but it's a small price to pay.

It does mean debug is on for all controllers but that's not a problem.

like image 33
Sarah K Avatar answered Oct 21 '22 07:10

Sarah K