10

I am developing a mvc component for both joomla 2.5 and 3.In many components i saw they added joomla's default command buttons like new, edit, publish, trash, options at top of their settings page in admin side. Eg. if one goes components->weblinks->links page, i am talking about those command buttons at top right.

So how do i add those command buttons in my component's settings page? when clicked it would do respective action and show respective view.For instance, if i click "new" button it will display my mvc component's add entry view as it is.

So how could i add fully workable joomla's command buttons in my component's settings page in admin side.

2 Answers 2

12

The best practice is to create the addToolBar() method inside your View class and then using JToolBarHelper class to create command buttons:

protected function addToolBar()
{
  JToolBarHelper::addNew('yourcontroller.add');
  JToolBarHelper::editList('yourcontroller.edit');
}

So these will call the task/function "add"/"edit" in your specified controller. Then simply call $this->addToolBar() in your View's display() method.

Reference Creating a toolbar for your component

4
  • I have only a controller file controller.php in my component and inside it i have a function function add() { JRequest::setVar('view', 'entry'); JRequest::setVar('layout', 'form'); parent::display(); } so in my view.html.php file i added JToolBarHelper::addNewX('controller.add'); then new button appears but when clicked it does not go to my view form instead adds a # to the url
    – dev-m
    Apr 27, 2014 at 20:12
  • Try to omit controller.task - JToolBarHelper::addNewX(); Apr 28, 2014 at 7:51
  • Added only JToolBarHelper::addNewX(); but not works.
    – dev-m
    Apr 28, 2014 at 12:52
  • Then you need to create a proper controller under controllers directory. See Adding backend actions Apr 28, 2014 at 17:14
5

You need to make sure the view that displays the buttons has a form to submit. The form name should be adminForm. The form should also have a hidden field named task and the dynamically generated token. I cannot recall the API off the top of my head, but something like JHtml::_('form.token'); (someone please correct this, if I'm mistaken)

This do the trick.

2
  • The problem i found out before was that i was using form name as adminform instead adminForm.it seems joomla kind of case sensitive!
    – dev-m
    May 8, 2014 at 20:33
  • It's more of a JavaScript thing than Joomla specific. When you click the buttons you are actually triggering a JS submit form function, so if the form can't be found then it quietly fails. May 8, 2014 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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