• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Defining regular cut off in Controller or Model?

Marcus

Well-known member
#1
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)
 

Marcus

Well-known member
#2
phpStorm tells me that "the expression is not allowed as a default value" which answers my question very well.
 

Daniel Hood

Well-known member
#3
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.
 

Daniel Hood

Well-known member
#5
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.