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
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.
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
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With