简体   繁体   中英

Joomla 3.x Override button functions in custom component

I'm trying to override the buttons in my joomla component.

I've managed fine with the save function by adding code into the controller.

            public function save($key = null, $urlVar = null)
                {
                    $uri = JUri::getInstance(); 


                    $requestData = JRequest::getVar('jform', array(), 'post', 'array');
                    $user =& JFactory::getUser();
                    $userId = $user->get( 'id' );

                    $idToUse = $requestData['id'];

I want to do the same thing with save and close and save and new but I can't figure out how to do it. I thought that I needed to go to the view.html and look at the custom functions:

            JToolBarHelper::title(JText::_('COM_SHOPPER_TITLE_SELECTOR'), 'selector.png');

            // If not checked out, can save the item.
            if (!$checkedOut && ($canDo->get('core.edit') || ($canDo->get('core.create'))))
            {
                JToolBarHelper::apply('selector.apply', 'JTOOLBAR_APPLY');
                JToolBarHelper::save('selector.save', 'JTOOLBAR_SAVE');
            }

            if (!$checkedOut && ($canDo->get('core.create')))
            {
                JToolBarHelper::custom('selector.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
            }

So I thought I just needed to add a function save2new() but I can't figure out how to make it work.

Any thoughts on where I'm going wrong would be great.

I guess you are looking for registerTask .

If you want to call save method for save2new task than you need to call registerTask inside constructor __constructor

$this->registerTask('save2new', 'save');

https://docs.joomla.org/API17:JController::registerTask

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM