1

I am doing bug fixes on already done Joomla project and I am a novice to Joomla. The issue is with the JToolBarHelper addNew button. We have two components- order and register. Both uses the add and edit buttons in front end. The function written for both component seems same in the view file.

protected function addToolBar()
    {
        if ($this->canDo->get('core.create')) 
        {
            JToolBarHelper::addNew('form.add', '_NEW');
        }
        if ($this->canDo->get('core.edit')) 
        {
            JToolBarHelper::editList('form.edit', '_EDIT');
        }
    }

For registration, both buttons works fine. On clicking add button it will go to page

www.test.net/index.php?option=com_register&view=form&layout=test&lang=en

What I also need to know is how this addNew function parameter works. Why it goes to the the layout test (which is correct in case of register layout). Is there something I miss? My real problem is, when I click on the add button in register, it goes to url with same params as above which is

www.test.net/index.php?option=com_order&view=form&layout=test&lang=en

and cause error that layout is missing.

Note: layout file "test" is there in register component but not in order.

1

You need to add the layout 'test' in the order component as well in the location : com_orders/views/form/tmpl/test.php

Then, this error will not be given.

Secondly, the addNew function works like following:

  1. In view.html.php: the addNew is a method defined in the core file of Joomla located in administrator/includes/toolbar.php.

    Refer for more: https://docs.joomla.org/JToolBarHelper

    Here, the first parameter is the controller name and the method defined in that controller. Like in your code, form is the controller name and add is the task/function defined in it. Well, add and edit are core tasks so it is not necessary that they might be present in your controller file. It is taken by default.

  2. In controller.php: The add function is present which is known as task and it directs you to the page where a form from where user can submit a new record in the database.

    Refer here for details on tasks and controllers: https://docs.joomla.org/JController_and_its_subclass_usage_overview

Hope this helps

  • Thank you very much for the valuable feedback. Working of addNew make sense now. For the first one the solution does not seem adequate. Even if the error is gone, it is not going to correct location which i need which is www.test.net/index.php?option=com_order&view=form&layout=edit&lang=en – Thejas Oct 19 '16 at 10:58
  • if you find the answer useful you can upvote it :) and now if you want to redirect to edit layout then check your controller, there might be a method defined and in that the test layout will be present. You can just change it to edit. – Liz. Oct 19 '16 at 11:11
  • already checked and did not find any such code in that controller. anyway my upvote for you but cant be seen unless there is enough reps :) – Thejas Oct 19 '16 at 11:48

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.