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

Not a Bug Extending an action with a return of ControllerResponse_View

Discussion in 'Resolved Bug Reports' started by Jeremy, Nov 6, 2010.

  1. Jeremy

    Jeremy XenForo Moderator Staff Member

    OK,

    Here's a confusing on. Mike sorta knows the situation. For my add-on BB Code Manager I needed to extend XenForo_ControllerPublic_Help. According to Mike, if I did:
    PHP:
    public function actionBbCode()
    {
         
    $var parent::actionBbCode();
         
    $var->params['addMyTemplateVar'] = 'Hello';
         return 
    $var;
    }
    That it'd work. In essence, this sorta did. It added addMyTemplateVar to the params array just fine. However, it seems that it rendered the view already, so it produced a display error (since I was using it in a foreach()). Now, my next "solution" was to do that, then create a new ResponseView with the $params again. Now, this worked, but it didn't have mediaSites defined in $var->params. Which it should, if I was correct (I had some guidance from Mike here)? Here's my final code:
    PHP:
        public function actionBbCodes()
        {
            
    $viewParams parent::actionBbCodes();
            
    $viewParams->params['mediaSites'] = $this->getModelFromCache('XenForo_Model_BbCode')->getAllBbCodeMediaSites();
            
    $viewParams->params['customBbCodes'] = $this->getModelFromCache('KingK_BbCodeManager_Model_CustomBbCode')->getAllActiveCustomBbCodes();

            return 
    $this->_getWrapper('bbCodes',
                
    $this->responseView('XenForo_ViewPublic_Help_BbCodes''help_bb_codes'$viewParams->params)
            );
        }
    So my solution was to ad to $var->params[] the ['mediaSites'] again using the model call found in parent. But, again, this is basically what I hard originally started with. Maybe params[] was the wrong variable to use, but I basically end up with the same code I started with, just with a more unreadable sense: the 'copied' code from XenForo. Maybe a bug? Maybe not? Maybe just using the wrong variable?
     
  2. Shadab

    Shadab Well-Known Member

    Assuming you want to make available a variable in the original template help_bb_codes;
    Have you tried doing something like: (untested)
    PHP:
    public function actionBbCode()
    {
        
    $wrapper parent::actionBbCode();
        
    $wrapper->subView->params['addMyTemplateVar'] = 'Hello';

        return 
    $wrapper;
    }
     
    Vladislav Rastrusny and Mike like this.
  3. Mike

    Mike XenForo Developer Staff Member

    Yes in this particular instance, there's a sub-view. The outer view is the wrapping template. I haven't tested it, but Shadab's code should be correct.
     
  4. Mike

    Mike XenForo Developer Staff Member

    On a side note, if you're struggling with figuring out what things are, you can use Zend_Debug::dump($var); to get a var_dump (that you can view more easily). That style of debugging is very very common in the PHP world (there are proper debuggers as well, but that depends on your IDE and your level of comfort with using them).
     
    Chris D, Jeremy and Darkimmortal like this.
  5. Jeremy

    Jeremy XenForo Moderator Staff Member

    I use Panic's Coda, so I have no real debugger... And thanks for the help you guys (again, to you Mike!). Zend_Debug::dump() may REALLY really help me in the future, and I'll be using that a lot. :p
     
  6. Kier

    Kier XenForo Developer Staff Member

    You can also use {xen:helper dump, $variable} within a template :)
     
  7. Jeremy

    Jeremy XenForo Moderator Staff Member

    Even better!
     

Share This Page