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

Get visitor info with Phalcon

Discussion in 'XenForo Development Discussions' started by JackBauer, Sep 28, 2014.

  1. JackBauer

    JackBauer Member

    I have a website that uses Phalcon. The directory structure looks like this:
    Code:
    mysite
    -- app
    ---- controllers
    ------ IndexController.php
    -- forums
    ---- (XenForo stuff here)
    
    I'm trying to register a visitor component with the Phalcon IoC container like this:
    Code:
    $di->set('visitor', function () {
      \XenForo_Autoloader::getInstance()->setupAutoloader('/mysite/forums/library');
      \XenForo_Application::initialize('/mysite/forums/library', '/mysite/forums', true, array('resetOutputBuffering' => false));
      \XenForo_Session::startPublicSession();
    
      $visitor = \XenForo_Visitor::getInstance();
    
      return $visitor;
    });
    
    Then my controller action is pretty simple:
    Code:
    public function indexAction()
    {
      echo $this->visitor->get('username');
    }
    
    The problem is this displays absolutely nothing on the page. There are no errors in XenForo logs, Apache logs or otherwise. If I put the guts of that function in my controller action it works just fine:
    Code:
    public function indexAction()
    {
      \XenForo_Autoloader::getInstance()->setupAutoloader('/mysite/forums/library');
      \XenForo_Application::initialize('/mysite/forums/library', '/mysite/forums', true, array('resetOutputBuffering' => false));
      \XenForo_Session::startPublicSession();
    
      $visitor = \XenForo_Visitor::getInstance();
    
      echo $visitor->get('username');
    }
    
    Anyone know anything about Phalcon that can help me with this?
     
  2. JackBauer

    JackBauer Member

    Nevermind. I forgot to put

    Code:
    <?php echo $this->getContent(); ?>
    
    in my view. I figured this out after I tried removing the view entirely, which worked too.
     

Share This Page