【问题标题】:how to use JHTML::_('behavior.modal') in Joomla?如何在 Joomla 中使用 JHTML::_('behavior.modal')?
【发布时间】:2012-01-26 14:23:26
【问题描述】:

我正在创建一个组件,

controllers
    theatercontroller
    facilitycontroller
Models
    theater
    facility
view
    theater
    facility

我想要的是通过单击按钮并打开模式窗口来从剧院视图中添加新设施。我试过但没有用。我研究了一些组件,但像我这样的人很难理解它。请我需要一个简单的例子和​​解释来理解它。

【问题讨论】:

    标签: joomla joomla1.5 joomla-extensions


    【解决方案1】:

    你可以使用这个函数来获得一个模态按钮

    static public function getModalButtonObject($name,$text,$link,$width=750,$height=480)
    {
        JHTML::_('behavior.modal', "a.{$name}");  // load the modal behavior for the name u given
            $buttonMap = new JObject();   // create an Jobject which will contain some data, it is similar like stdClass object
            $buttonMap->set('modal', true);
            $buttonMap->set('text', $text );
            $buttonMap->set('name', 'image');
            $buttonMap->set('modalname', $name);
            $buttonMap->set('options', "{handler: 'iframe', size: {x: ".$width.", y: ".$height."}}");
            $buttonMap->set('link', $link);
            return $buttonMap;
    }
    

    而HTML可以写成

    <a id="<?php echo $buttonMap->modalname; ?>" class="<?php echo $buttonMap->modalname; ?>" title="<?php echo $buttonMap->text; ?>" href="<?php echo $buttonMap->link; ?>" rel="<?php echo $buttonMap->options; ?>"><?php echo $buttonMap->text; ?></a>
    

    【讨论】:

    • 感谢您的代码。我是新手,请您解释一下那里发生了什么以及如何使用它。
    • 它没有什么特别之处。我刚刚为按钮加载了一个模态行为,并创建了一个可以在 HTML 中使用的 JObject。
    【解决方案2】:

    它不必那么复杂。许多模板已经开启了模态行为,但如果它们没有,您只需将其添加到头部 -

    <?php JHTML::_('behavior.modal'); ?>
    

    然后将其添加到您要在模式窗口中打开的任何链接 -

    class="modal"
    

    其他都是可选的。

    【讨论】:

    • 我已经按照你的方式使用它它加载正常但是当我保存它时它会加载带有菜单和工具栏的视图。我不知道如何预防。
    • 你在模态窗口中加载了什么,你在保存什么?
    • 你需要在模态窗口加载的url中添加&tmpl=component
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多