0

I am trying to add a couple of custom toolbar buttons to my component, and at the moment the buttons are showing alright but can't get them to work.

My main problem is how to pass the id variable from the view layout to the sub-controller to perform a task in the case update a single column in the database.

These are my code structure

THE VIEW (view.html.php)

class LoanmanagerViewLoan extends JViewLegacy
{

protected $loanDetail;
public function display($tpl = null){       

    //Data from loanlist Model
    $model=$this->getModel('Loan');
    $this->loanDetail = $model->get_loan_detail();

    $this->addToolbar();
    parent::display($tpl);
}

protected function addToolbar()
{

    // Get the toolbar object instance
    $bar = JToolbar::getInstance('toolbar');

    JToolBarHelper::Title(JText::_('Loan Details'));    

    //TRYING TO MAKE THIS BUTTON WORK
    JToolBarHelper::custom('loan.approve', 'approve.png', 'icon-save.png', 'Approve Loan', false, false);

    JToolBarHelper::custom('loan.deny', 'deny.png', 'deny.png', 'Deny Loan', false, false);
}
}

VIEW LAYOUT (tmpl/default.php)

JHtml::_('behavior.formvalidator');  

 <form action="<?php echo JRoute::_('index.php?option=com_loanmanager&view=loan&type=softloan&id='. (int) $loan->id); ?>" method="post" name="adminForm" id="loan-form" enctype="multipart/form-data">



<input type="hidden" name="option" value="com_loanmanager" />
<input type="hidden" name="task" value="" />

<?php echo JHtml::_('form.token'); ?>
</form>

SUBCONTROLLER (controllers/loan.php)

class LoanmanagerControllerLoan extends JControllerLegacy
 {



public function approve()
{
    $jinput = JFactory::getApplication()->input;        
    $id = $input->post->get('id', 0, 'INT');            

    //Perform some SQL query with the $id
    return parent::display();
}   



 }
David Addoteye
  • 1,587
  • 1
  • 19
  • 31

1 Answers1

0

you need to write an input with the id in the form itself.

<input type="hidden" name="id" value="<?= (int) $loan->id ?>" />

alternatively, don't get the id from post, as you have put it in the action get url of the form

$id = $input->getInt('id');
JulienV
  • 775
  • 7
  • 12
  • @David please do your part to progress your questions to a system-recognized resolution. If this answer solves your issue, please award the green tick. If there is still something left to resolve, please clarify to Julien so that his answer can be adjusted. We must all collaborate to make StackOverflow and JoomlaStackExchange increasingly powerful resources. When someone volunteers their time to effectively support you in your development issue, you express your appreciation with upvotes/acceptance. – mickmackusa Jun 29 '18 at 00:10