【问题标题】:adding toolbar menu item in joomla 1.5 component.在 joomla 1.5 组件中添加工具栏菜单项。
【发布时间】:2012-07-30 02:57:20
【问题描述】:

我在 joomla 1.5 组件的工具栏菜单中添加工具栏添加按钮时遇到问题。 我需要以标准方式添加一个添加自定义按钮,因此我的按钮被添加到我的菜单中,但它不起作用我需要一个功能来帮助我从按钮中获取参数,例如我的任务(啊啊)。

/*
ToolBarHelper::custom('aaaa', 'new', 'new', 'Add Article', 'add_article', false);
*/

这是我如何获取任务参数的整个工具栏类。

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

/**
 * @package Joomla
 * @subpackage Config
 */
class TOOLBAR_video 
{

function _DEFAULT() {
    /*
     * DEVNOTE: This should make sense by itself now... 
     */
    JToolBarHelper::title(   JText::_( 'Video Manager' ), 'generic.png' );

            JToolBarHelper::custom('aaaa', 'new', 'new', 'Add Article', 'add_article', false);
    JToolBarHelper::help( 'screen.video' );


 );
}
}

【问题讨论】:

    标签: php joomla components toolbar


    【解决方案1】:

    它开始唤醒你所要做的就是覆盖函数 submitbutton 函数 这个函数位于includes/js/joomla.javascript.js,所以你应该重写这个函数来使用它作为自定义

    submitbutton(pressbutton) {
      submitform(pressbutton);
    } 
    

    经过一番研究,我在enter link description here找到了joomla usfull文章,所以我就这样写了。

       function submitbutton(pressbutton) {
       // Some conditions
       document.adminForm.task.value=pressbutton;
       // More conditions
       submitform(pressbutton);
       }
    

    所以最后的结果是这样的

    <script>
               /**
                 * Function is Overwriting native submitbutton() function.
                 * A Custom button relies on javascript from
                 * includes/js/joomla.javascript.js to execute the task indicated by the user:
                 */
                function submitbutton(pressbutton) {
                    var url = '';
                    if (pressbutton == 'add_article') {
                        url = '<?php echo JURI::root(); ?>'+'administrator/index.php?option=com_video&controller=video&action=add_article';
                        post_to_url(url,{'add_article': 'add_article'} );
                    }
                    if (pressbutton == 'delete_article') {
                         url = '<?php echo JURI::root(); ?>'+'administrator/index.php?option=com_video&controller=articlelisting&action=delete_article';
                         post_to_url(url,{'add_article': 'add_article'} );    
                    }
    
                } 
                /**
                 * Function is creating form and submitting using given url
                 * @var url string //Joomla admin component constructor path with action
                 * @var params string //it has {'var1': 'value1','var2': 'value2'} notation
                 */
                function post_to_url(url, params) {
                    var form = document.createElement('form');
                    form.action = url;
                    form.method = 'POST';
    
                    for (var i in params) {
                        if (params.hasOwnProperty(i)) {
                            var input = document.createElement('input');
                            input.type = 'hidden';
                            input.name = i;
                            input.value = params[i];
                            form.appendChild(input);
                        }
                    }
    
                    form.submit();
                }
       </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多