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

Extend XenForo_ControllerAdmin_UserGroupPromotion

Discussion in 'XenForo Development Discussions' started by Slind, Nov 6, 2015.

  1. Slind

    Slind Active Member

    hey,

    I'm trying to extend the XenForo_ControllerAdmin_UserGroupPromotion class to add a variable to my MyAddon_user_criteria template which gets included into the user_group_promotion_edit template but it doesn't get executed. (Using load_class_controller)

    What is the issue here?

    PHP:
    <?php
    class MyAddon_ControllerAdmin_UserGroupPromotion extends XFCP_MyAddon_ControllerAdmin_UserGroupPromotion
    {
        public function 
    actionIndex()
        {
            
    $db = new Zend_Db_Adapter_Pdo_Mysql(array(
                
    'host'     => 'localhost',
                
    'port'     => '8889',
                
    'username' => 'root',
                
    'password' => 'root',
                
    'dbname'   => 'test'
            
    ));

            
    $sql 'SELECT `group` FROM `table`';

            
    $result $db->fetchCol($sql);

            
    $viewParams = array(
                
    'MyAddon_groups' => serialize($result)
            );

            return 
    $this->responseView('MyAddon_ControllerAdmin_UserGroupPromotion''MyAddon_user_criteria'$viewParams);
        }

    }
    PHP:
    <?php

    class MyAddon_Listener_Controller
    {
        public static function 
    extendController($class, array &$extend)
        {
            if (
    $class == 'XenForo_ControllerAdmin_UserGroupPromotion')
            {
                
    $extend[] = 'MyAddon_ControllerAdmin_UserGroupPromotion';
            }
        }
    }
     
  2. Robust

    Robust Well-Known Member

    You should use Zend_Db::factory(), not directly access an adapter.

    Did you register the listener properly?

    Why serialise it? Unless you're actually using a view here.
     
  3. Slind

    Slind Active Member

    [​IMG]
    As I currently print out the variable to see if it works.
     
  4. Robust

    Robust Well-Known Member

    Right, use Zend_Db::factory(). Use Zend_Debug::dump() to dump the value of $db and $result
     
  5. Slind

    Slind Active Member

    Okay, got this error with the debug (but the output looks fine):
    Code:
    array(2) {
      [0] => string(5) "value1"
      [1] => string(5) "value2"
    }
    An exception occurred: Argument 1 passed to XenForo_Controller::__construct() must be an instance of Zend_Controller_Request_Http, instance of XenForo_ViewRenderer_HtmlAdmin given, called in /Applications/MAMP/htdocs/forum/library/XenForo/ViewRenderer/Abstract.php on line 215 and defined in /Applications/MAMP/htdocs/forum/library/XenForo/Controller.php on line 81
     
  6. Slind

    Slind Active Member

    @Robust any idea what the error is about?
     
  7. Robust

    Robust Well-Known Member

    That only appears when you're dumping something or did it already appear before?
     
  8. Liam W

    Liam W Well-Known Member

    Why don't you just use the user_criteria code event, and then use template modifications to add the data.

    You can then extend the method (or use the template_create listener), to add the template param (although be sure to add it to the return value of the parent method, and return the return value of the parent method).

    Liam
     
  9. Slind

    Slind Active Member

    No but I no longer get the error if I use
    PHP:
    return $this->responseView('XenForo_ViewAdmin_UserGroupPromotion_Edit''MyAddon_user_criteria'$viewParams);
    but this overrides the $viewParams which xenforo sets. Not exactly sure what to do here.

    I did use template_create before but it seems to run my code then multiple times and not only once. And I want to list groups for selection like xenforo does for the xenforo groups. So criteria_user event comes later when I got the groups in the user group promotion edit
     
    Last edited: Nov 8, 2015

Share This Page