2

I am trying to upgrade a component from 2.5 to 3.x. But while doing so I am getting error from controller.php file. Error message is like the following: Fatal error: Call to a member function get() on a non-object in /home/abs/public_html/joomla34/administrator/components/com_refix/controller.php on line 20 Here is the code of controller.php file:

defined('_JEXEC') or die;

class PrefixController extends JControllerLegacy {
/**
 * constructor
 * 
 * @access public
 */
public function __construct() {

    require_once JPATH_COMPONENT . '/helpers/prefix.php';
    JFactory::getApplication()->input->get('view', $this->input->get('view', 'tableprefix'));
    parent::__construct();
    $view = $this->input->get('view');
    PrefixHelper::addSubMenu((isset($view)) ? $view : '');
}

/**
 * check new table prefix
 * 
 * @access private
 * @return boolean
 */
private function checkTablePrefix() {
    $new_prefix = $this->input->get('new_prefix');
    if(!preg_match('/^[a-zA-Z]+[a-zA-Z0-9_]*$/',$new_prefix)) {
        return false;
    } else {
        return true;
    }
}

/**
 * rename table prefix and update configuration.php file
 * 
 * @access public
 */
public function update() {
    $msg = '';
    if(!$this->checkTablePrefix()) {
        $msg = '<span class="prefix_error">' . JText::_('COM_PREFIX_PREFIX_NEW_PREFIX_DESC') . '</span>';
    } else {
        $model = $this->getModel('tableprefix');
        $new_prefix = $this->input->get('new_prefix');
        if($model->renamePrefix($new_prefix)) {
            $msg .= JText::_('COM_PREFIX_SUCCESS:TABLE_PREFIX_ALREADY_UPDATED');

            // update configuration file
            if($this->input->get("update_config") == '1') {
                // backup configuration file
                if($this->input->get("backup_before") == '1') {
                    $msg .= "<br />";
                    if($model->backupConfig()) {
                        $msg .= JText::_('COM_PREFIX_SUCCESS:BACKUP_THE_CONFIGURATION.PHP_FILE');
                    }  else {
                        $msg .= '<span class="prefix_error">' . JText::_('COM_PREFIX_ERROR:CONFIGURATION.PHP_FILE_COULD_NOT_BE_BACKUP') . '</span>';
                    }
                }

                $msg .= "<br />";
                if($model->editConfig($new_prefix)) {
                    $msg .= JText::_('COM_PREFIX_SUCCESS:CONFIGURATION_FILE_HAS_BEEN_UPDATED');
                }  else {
                    $msg .= '<span class="prefix_error">' . JText::_('COM_PREFIX_ERROR:CONFIGURATION_FILE_COULD_NOT_BE_UPDATE,PLEASE_MANUAL_UPDATE') . '</span>';
                }
            }
        } else {
            $msg .= '<span class="prefix_error">' . JText::_('COM_PREFIX_ERROR:TABLE_PREFIX_COULD_NOT_BE_UPDATE') . '</span>';
        }
    }
    ob_end_clean();
    JResponse::setHeader("Pragma", "no-cache");
    JResponse::setHeader("Expires","0");
    echo $msg;
    exit;
} // end function    
}
  • line number 20 is: JFactory::getApplication()->input->get('view', $this->input->get('view', 'tableprefix')); – indy Apr 23 '15 at 15:38
3

Not 100% this is your issue, but you have no display method and as a result you're also not calling the super class display method. Try changing this method:

public function __construct() {

To:

public function display($cachable = false, $urlparams = false) {
    require_once JPATH_COMPONENT . '/helpers/qtableprefix.php';
    $this->input = JFactory::getApplication()->input;
    $this->input->get('view', $this->input->get('view', 'tableprefix'));
    $view = $this->input->get('view');
    QTablePrefixHelper::addSubMenu((isset($view)) ? $view : '');
    parent::display($cachable, $urlparams);
    return $this
}

See if that corrects your issue.

  • yahh..its a correct answer..i wish you could have give me this answer a bit earlier..I figured it out by myself and yes its the correct answer that I was looking for. – indy Apr 23 '15 at 21:25
  • lol, I would have had I scene it earlier. glad you got it working and thanks for accepting the answer regardless! – Brian Bolli Apr 23 '15 at 21:28
  • yahh..its like I have to spend 2-3 hours just to figure that out..so yahh..it would have a big help if you could have had scene it earlier..but nevertheless its the damn correct answer. so cheers :) – indy Apr 23 '15 at 21:30
3

Line 20 looks pretty messed up. I'm not sure what you are trying to do with it? In general though the error is because you haven't defined $this->input:

try using this instead:

public function __construct() {

    require_once JPATH_COMPONENT . '/helpers/qtableprefix.php';
    $this->input = JFactory::getApplication()->input;
    $this->input->get('view', $this->input->get('view', 'tableprefix'));
    parent::__construct();
    $view = $this->input->get('view');
    QTablePrefixHelper::addSubMenu((isset($view)) ? $view : '');
}

note that

$this->input->get('view', $this->input->get('view', 'tableprefix'));

won't do anything though as you are not assigning the input to a variable. As far as I can tell you could simply remove the line altogether

  • thank you for your help..but I am now getting error like: 500 View not found [name, type, prefix]: qtableprefix, html, qtableprefixView – indy Apr 23 '15 at 16:44
  • $this->input is defined in the super class and is an instance of the JInput object. – Brian Bolli Apr 23 '15 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.