1. 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?

Discussion in 'XenForo Development Discussions' started by Marcus, Aug 3, 2015.

  1. Marcus

    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)
     
  2. Marcus

    Marcus Well-Known Member

    phpStorm tells me that "the expression is not allowed as a default value" which answers my question very well.
     
  3. Daniel Hood

    Daniel Hood Well-Known Member

    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.
     
    Marcus likes this.
  4. Marcus

    Marcus Well-Known Member

    Great advice and its very logical.

    Would you define the cutoff in the controller or in the model ?
     
  5. Daniel Hood

    Daniel Hood Well-Known Member

    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.
     

Share This Page