Call to a member function createTemplateObject() on a non-object

Jaxel

Well-known member
I'm getting this error with a bbcode code. The bbcode worked in XF1.2... but has since stopped working on XF1.3. The odd thing is, I have other bbcode with my other mods that look very similar, but they all work perfectly fine. Whats wrong with this one?

Code:
<?php

class EWRrio_BbCode_Formatter extends XFCP_EWRrio_BbCode_Formatter
{
    protected $_tags;

    public function getTags()
    {
        $this->_tags = parent::getTags();

        $this->_tags['stream'] = array(
            'trimLeadingLinesAfter' => 1,
            'callback' => array($this, 'renderTagStream'),
        );

        return $this->_tags;
    }

    public function renderTagStream(array $tag, array $rendererStates)
    {
        $content = $this->renderSubTree($tag['children'], $rendererStates);
       
        if ($tag['option'] && $content)
        {
            if ($service = XenForo_Model::create('EWRrio_Model_Services')->getServiceByBBcode($tag['option']))
            {
                $values = explode(',', $content);
                $service['channel_value1'] = $values[0];
                $service['channel_value2'] = !empty($values[1]) ? $values[1] : '';
               
                $channel = XenForo_Model::create('EWRrio_Model_Channels')->parseReplacements($service);
                $channel['channel_chat'] = '';
            }
        }
        else if ($content)
        {
            $channel = XenForo_Model::create('EWRrio_Model_Channels')->getChannelByID($content);
        }
       
        if (!empty($channel))
        {
            if ($this->_view)
            {
                $template = $this->_view->createTemplateObject('EWRrio_BBcode', array('channel' => $channel));
                return $template->render();
            }
           
            return '<a href="'.XenForo_Link::buildPublicLink('streams/stream', $channel).'">' . $channel['channel_value1'] . '</a>';
        }
       
        return '[stream' . ($tag['option'] ? '='. $tag['option'] : '') . ']'.$content.'[/stream]';
    }
}


And to reiterate, this code, which uses the same exact call to createTemplateObject, is working perfectly fine:
Code:
<?php

class EWRcustom_BbCode_Formatter extends XFCP_EWRcustom_BbCode_Formatter
{
    protected $_tags;

    public function getTags()
    {
        $this->_tags = parent::getTags();

        $this->_tags['spoiler'] = array(
            'trimLeadingLinesAfter' => 2,
            'callback' => array($this, 'renderTagSpoiler')
        );

        return $this->_tags;
    }

    public function renderTagSpoiler(array $tag, array $rendererStates)
    {
        $content = $this->renderSubTree($tag['children'], $rendererStates);
        $spoiler = $tag['option'];

        if ($this->_view)
        {
            $template = $this->_view->createTemplateObject('EWRcustom_spoiler', array(
                'content' => $content,
                'spoiler' => $spoiler
            ));
            return $template->render();
        }
        else
        {
            $name = '<div>' . new XenForo_Phrase('spoiler_warning') . ($spoiler ? ': '.$spoiler : '') . '</div>';
            return '<blockquote>' . $name . $content . '</blockquote>';
        }
    }
}
 
It seems $this->_view is being overwritten. Try dumping it to see if it's the object you're expecting.

PHP:
if ($this->_view)
{
 var_dump($this->_view);
}
 
It seems $this->_view is being overwritten. Try dumping it to see if it's the object you're expecting.

PHP:
if ($this->_view)
{
var_dump($this->_view);
}
Thats not really possible. The view is such a large variable, its not feasible to dump.
 
I figured it out... I didn't put in a fallback for non-view instances.

In 1.2, it seemed to fail silently... in 1.3 it doesn't.
 
Top Bottom