Undefined Variable: errorPhraseKey

Gossamer

Active member
I've been making good progress with my add-on, but when trying to check permissions on a delete function, I end up receiving the error below:

Server Error
Undefined variable: errorPhraseKey

  1. XenForo_Application::handlePhpError() in Goss/Reservations/ControllerPublic/Reserves.php at line 108
  2. goss_Reservations_ControllerPublic_Reserves->actionDelete() in XenForo/FrontController.php at line 347
  3. XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
  4. XenForo_FrontController->run() in C:/xampp/htdocs/Xenforo_DEV/index.php at line 13

And here is my code.

ControllerPublic
PHP:
    public function actionDelete()
    {
        $id = $this->_input->filterSingle('id', XenForo_Input::UINT);
  
        if (!$this->_getReserveModel()->canDeleteReserve($errorPhraseKey))
        {
            throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
        }
      
        //Create a instance of our DataWriter
        $dwReserve = XenForo_DataWriter::create('Goss_Reservations_DataWriter_Reserves');
        $dwReserve->setExistingData($id);
        $dwReserve->delete();
      
        return $this->responseRedirect(
                    XenForo_ControllerResponse_Redirect::SUCCESS,
                    $this->getDynamicRedirect()
                );
    }

Model
PHP:
    public function canDeleteReserve(array $ViewingUser = null, &$errorPhraseKey = '', array $nodePermissions = null)
    {
        $this->standardizeViewingUserReference($viewingUser);
      
        if(!$viewingUser['user_id'])
        {
            return false;
        }
      
        if(!XenForo_Permission::hasPermission($viewingUser['permissions'], 'Reserves', 'deleteReserve'))
        {
            return false;
        }
        else
        {
            return true;
        }
    }
 
Last edited:
Your function canDeleteReserve() has $ViewingUser as the first parameter but you are calling it with the $errorPhraseKey as the first parameter instead of the second.
Also noticed that you are using $nodePermissions as a parameter but do not actually use it inside the function. Is your permission a general one or node specific?

Edit:
Also, $ViewingUser should be $viewingUser
 
Last edited by a moderator:
Thanks! Switching the order fixed it.

And for the permission, it's a general permission. It's not node specific.
 
Top Bottom