Defining regular cut off in Controller or Model?

Marcus

Well-known member
Which of the both code looks nicer to you ? The model will only be accessed with a 15 minutes cut off which I did not want to hard code into the model, so I wonder which looks better.
PHP:
$cutOff = XenForo_Application::$time - 60 * 15;
$serverErrors = $model->getErrorLogs($cutOff);
...
function getErrorLogs($cutOff)

PHP:
$serverErrors = $model->getErrorLogs();
...
function getErrorLogs($cutOff = XenForo_Application::$time - 60 * 15)
 
phpStorm tells me that "the expression is not allowed as a default value" which answers my question very well.
 
phpStorm tells me that "the expression is not allowed as a default value" which answers my question very well.
You could replace
PHP:
function getErrorLogs($cutOff = XenForo_Application::$time - 60 * 15)
with

PHP:
function getErrorLogs($cutOff = 0) { if ($cutOff === 0) { $cutOff =  XenForo_Application::$time - 60 * 15; } // rest of your function.
 
Great advice and its very logical.

Would you define the cutoff in the controller or in the model ?
 
Either.. Both.. No reason to not allow the controller to send the cutoff and then if it doesn't send it, default back to something like you are anyways.
 
Back
Top Bottom