Template Error

Gossamer

Active member
Hello! So, I'm trying to pass the variable $ExistingReserve from my Controller into a template. However, when the template loads I receive this error:

Template Errors: goss_reserves
  1. htmlspecialchars() expects parameter 1 to be string, array given in C:\xampp\htdocs\Xenforo_DEV\library\XenForo\Template\Abstract.php(265) : eval()'d code, line 5:
    4:
    5: Test: ' . htmlspecialchars($ExistingReserve, ENT_QUOTES, 'UTF-8') . '
    6:

Here is the relevant part of my ControllerPublic:
PHP:
    public function actionIndex()
    {
        //Check for Existing Reserve
        $visitor = XenForo_Visitor::getInstance();
       
        $reserveModel = $this->_getReserveModel();
       
        if($reserveModel->getReserveByUser($visitor['user_id']))
        {
            $ExistingReserve = $reserveModel->getReserveByUser($visitor['user_id']);
        }
        else
        {
            $ExistingReserve = 0;
        }
       
        //Get all rows from our table and other data to pass to the template so it can be used
        $viewParams = array(
            'Reserves' => $this->_getReserveModel()->getAllReserves(),
            'ExistingReserve' => $ExistingReserve);
       
        return $this->responseView('Reservations_ViewPublic_Reserves', 'goss_reserves', $viewParams);
    }

And my model with the getReserveByUser function:
PHP:
    public function getReserveByUser($user_id)
    {
        return $this->_getDb()->fetchRow('SELECT * FROM xf_goss_reservation WHERE user_id = ?', $user_id);
    }
It looks like the error comes from how I'm attempting to set $ExistingReserve using the getReserveByUser function. What's the correct way to pass the information?
 
Woops. This actually turned out to be a really silly error. I forgot to actually call the field I was looking for in the template and instead was calling the whole array. XD

All set now!
 
Back
Top Bottom