如何使Joomla 3x自定义工具栏按钮工作

时间:2018-05-26 03:42:02

标签: joomla joomla3.0 joomla-component

我正在尝试为我的组件添加几个自定义工具栏按钮,此时按钮显示正常,但无法让它们工作。

我的主要问题是如何将id变量从视图布局传递到子控制器,以便在更新数据库中的单个列的情况下执行任务。

这些是我的代码结构

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);
}
}

查看布局(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();
}   



 }

1 个答案:

答案 0 :(得分:0)

你需要在表单中写一个带id的输入。

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

或者,不要从帖子中获取id,因为你已经把它放在了表格的动作获取网址

$id = $input->getInt('id');