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

Textbox not populating

Discussion in 'XenForo Development Discussions' started by silence, May 29, 2013.

  1. silence

    silence Well-Known Member

    SO! I'm extending Merc's donation manager, and everything is working so far, except one astetic thing:
    The text field that I'm inputting info isn't being populated with the information currently stored in the db. If I write something and save, it populates the database just fine! It just doesn't show that info.

    The only thing I THINK is causing it is some issue with _getFields():

    PHP:
        protected function _getFields()
        {
            
    $fields parent::_getFields();
     
            
    $fields['merc_goal']['merc_callback_class'] = array(
                
    'type'  => self::TYPE_STRING,
                
    'required' => false,
                
    'default' => '',
                
    'maxLength' => 250,
                
    'requiredError' => 'please_enter_valid_callback_class'
            
    );
     
            
    $fields['merc_goal']['merc_callback_method'] = array(
                
    'type' => self::TYPE_STRING,
                
    'required' => false,
                
    'default' => '',
                
    'maxLength' => 250,
                
    'requiredError' => 'please_enter_valid_callback_method'
            
    );
     
            return 
    $fields;
        }
     
  2. tyteen4a03

    tyteen4a03 Well-Known Member

    Did you set the proper <input> value parameter?
     
  3. silence

    silence Well-Known Member

    HTML:
    <xen:controlunit label="{xen:phrase php_callback}:">
     
    <xen:textbox name="merc_callback_class" value="{$field.merc_callback_class}" placeholder="{xen:phrase class}" size="25" />
     
    ::
     
    <xen:textbox name="merc_callback_method" value="{$field.merc_callback_method}" placeholder="{xen:phrase method}" size="25" />
     
    </xen:controlunit>
    Derp yeah you were right. Thanks mate!
     
  4. silence

    silence Well-Known Member

    One more question:
    I'm extending a model blahblahblah, and I'm extending one of it's functions:

    PHP:
        public function commit($token)
        {
            
    $this->finalizeCallback($token);
           
            return 
    parent::commit($token);
        }
    However, it completely breaks the function commit in the model I'm extending. I thought returning the parent should make it execute as normal but that doesn't seem to work. What is the safest way to do this?
     
  5. tyteen4a03

    tyteen4a03 Well-Known Member

    I can't comment without seeing the whole code, but you're basically returning the result of the parent function, which is equal to not overriding the function at all.
     
  6. silence

    silence Well-Known Member

    How would you extend a function in XF? And I'm not posting the code since it's a paid plugin and I feel permission from the author would be needed.
     
  7. tyteen4a03

    tyteen4a03 Well-Known Member

    Sorry, I meant overriding.
     
  8. silence

    silence Well-Known Member

    Ok I'm still lost. I'm extending the model in my listener.php file, and i created the code listener in XF.
    This is what I'm doing:

    PHP:
        public static function loadClassModel($class, array &$extend)
        {       
            if (
    $class == 'Merc_DonationManager_Model_Goal')
                
    $extend[] = 'XenoGamers_Model_Goal';
            elseif (
    $class == 'Merc_DonationManager_Model_Transaction')
                
    $extend[] = 'XenoGamers_Model_Transaction';
        }
     
  9. tyteen4a03

    tyteen4a03 Well-Known Member

    Really can't comment without seeing the entire code. What does finalizeCallback do?
     
  10. silence

    silence Well-Known Member

    PHP:
        protected function finalizeCallback($token)
        {
            
    $transaction $this->getTransaction($token);
     
            
    $fields Merc_DonationManager_DataWriter_Goal::_getFields();
     
            
    $entry = array(
                
    'username' => $this->getModelFromCache('XenForo_Model_User')->getUserById($transaction['user_id']),
                
    'user_id' => $transaction['user_id'],
                
    'goal_id' => $transaction['goal_id'],
                
    'amount' => $transaction['amount'],
                
    'note' => $transaction['note'],
                
    'anonymous' => $transaction['anonymous'],
                
    'merc_callback_class' => $fields['merc_callback_class'],
                
    'merc_callback_method' => $fields['merc_callback_method']
            );
     
            
    $this->_getTransactionModel()->executeCallback($entry);
        }
     
        protected function 
    _getTransactionModel()
        {
            return 
    $this->getModelFromCache('Merc_DonationManager_DataWriter_Goal');
        }
     
  11. xf_phantom

    xf_phantom Well-Known Member

    start debugging! (use a php debugger or stupid echo/var_dump commands)
    $fields = Merc_DonationManager_DataWriter_Goal::_getFields(); won't work

    1. The method isn't static
    2. it's not a public method
     
  12. silence

    silence Well-Known Member

    Ok I rewrote everything so in datawriter it calls a single model file. The only issue I have now is that how do I get the custom callback to execute? Here is the final model:

    PHP:
    class XenoGamers_Model_Callback extends XenForo_Model
    {
        public function 
    executeCallback(array $entry, array $callback)
        {
            if (
    XenForo_Application::autoload($callback['callback_class']) && method_exists($callback['callback_class'], $callback['callback_method']))
            {
                
    call_user_func(array($callback['callback_class'], $callback['callback_method']), $entry);
            }
        }
    }
     
  13. silence

    silence Well-Known Member

    Anyone know how to execute a callback in the way I described above? I can't find anything in the xf core.
     

Share This Page