Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I test whether running from CakePHP Console?

Tags:

php

cakephp

I have a CakePHP Console Shell that works fine until a Model->afterFind() tries to add some data to the results which includes adding links, which doesn't seem to work while being called from the Console.

Is there a way to test in the Model->afterFind() callback function whether it's being called from a Console Shell, so that I can skip the troublesome section that I don't need anyway?

Thanks, Ian

like image 248
ianmjones Avatar asked Feb 25 '23 13:02

ianmjones


1 Answers

I'm not too sure whether there's a Cake way to do it, but you can do it via regular PHP

 if(php_sapi_name() == 'cli' && empty(getClientIP())) {
      //running via CLI
 } else {
      //running normally
 } 
like image 96
JohnP Avatar answered Mar 08 '23 00:03

JohnP