1

在 PyroCMS 中,我使用session:messages标签向用户显示消息。这运作良好,但我想为每条消息添加一个关闭按钮,这需要在每条消息中放置一个跨度。例如:

<div class="alert success">
  You have logged in successfully. <span class="close">X</span>
</div>

每条消息都包装在一个 div 中,通过设置session:messages标签的属性来给它一个类。没有指定输出的内置方法。如何覆盖messages()session.php 中的函数,添加一个新属性来附加这个关闭按钮?

到目前为止,我已经尝试过:

  1. 将system/cms/plugins/session.php复制到 *addons/shared_addons/plugins/session.php* 并修改messages()函数。使用的是核心功能,而不是我希望的新插件。

  2. 如上所述复制插件,然后将其类更改为My_Plugin_Session extends Plugin_Session希望其功能随后覆盖核心 Plugin_Session 类。没运气。

4

3 回答 3

3

无法扩展核心中的某些内容(例如库和帮助程序) - 我认为这也适用于插件。

在这种情况下,如果我是你(我可能必须为我的下一个项目这样做,因为这些可关闭的警报通常在Twitter Bootstrap等中)我只需直接编辑/system/cms/plugins/session.php并将<span>关闭按钮的额外内容添加到成功、通知和错误条件(“if”语句)中。

在一个典型的网站上,我想不出你会需要一些与其他人不同的警报显示的情况(除了不同的颜色,当然取决于结果,你可以在 CSS 中使用类名来做到这一点)。

如果您正在使用 Git(您已经克隆或分叉了官方 PyroCMS 存储库创建了自己的分支),那么您对未来的更新绝对没问题 - 如果在未来版本中会话插件发生更改,任何更改都将被合并到您的代码会自动生成,或者如果 Git 无法弄清楚,它会向您显示差异并提示您手动修复它。

注意 - 基于管理界面,还有一些其他解决方案可以解决这个特定问题(您可能已经注意到那里的 flash 消息是可关闭的)。

您可以创建一个部分 - 它可以包含 PHP,而不仅仅是 Lex 标记 - 例如,查看/system/cms/themes/pyrocms/views/admin/partials/notices.php类似这样的内容(根据需要编辑并复制通知和错误):

<?php if ($this->session->flashdata('success')): ?>
<div class="alert success">
    <?php echo $this->session->flashdata('success'); ?>
</div>
<?php endif; ?>

PyroCMS 管理员实际上使用liveQuery<span>在浏览器中附加关闭按钮
来源:/system/cms/modules/wysiwyg/js/wysiwyg.js

// Add the close link to all alert boxes
$('.alert').livequery(function(){
    $(this).prepend('<a href="#" class="close">x</a>');
}); 
于 2012-08-15T21:23:41.857 回答
2

我这样做了,它运行完美,不需要 jQuery 以外的其他插件。

在模板布局中添加:

{{ session:messages success="message success" notice="message info" error="message error" }}

JavaScript

$(function() {
    $('.message').prepend('<a class="baxclose" id="baxclose"></a>');
    $('#baxclose').click(function(){
        $('.message').fadeOut('slow');
    });
});

和CSS:

 a.baxclose{
    float:left;
    width:30px;
    height:30px;
    background:transparent url(../img/close-icon.png);
    margin-top: -30px;
    margin-left: -30px;
    cursor:pointer;
}
.message {
    padding: 20px 20px;
    -moz-border-radius: 3px;
    -webkit-border-radius: 3px;
    border-radius: 3px;
    margin-bottom: 10px;
    -moz-box-shadow:inset 0 2px 3px rgba(255,255,255,0.5), 0 2px 3px rgba(0,0,0,0.1);
    -webkit-box-shadow:inset 0 2px 3px rgba(255,255,255,0.5), 0 2px 3px rgba(0,0,0,0.1);
    box-shadow:inset 0 2px 3px rgba(255,255,255,0.5), 0 2px 3px rgba(0,0,0,0.1);
    zoom: 1;
    margin-bottom: 20px;
}
    .message h3 {
        margin-top: 0;
        font-size: 12px;
        font-weight: bold;
    }
    .message p {
        margin-bottom: 0;
    }

.message.info {
    border: 1px solid #cadcea;
    background-color: #cdf;
    background-image: -o-linear-gradient(top,  #eef,  #cdf);
    background-image: -ms-linear-gradient(top,  #eef,  #cdf);
    background-image: -moz-linear-gradient(top,  #eef,  #cdf);
    background-image: -webkit-gradient(linear, left top, left bottom, from(#eef), to(#cdf));
    background-image: -webkit-linear-gradient(top,  #eef,  #cdf);
    background-image: linear-gradient(top,  #eef,  #cdf);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#EEEEFF', endColorstr='#CCDDFF');
    color: #225b86;
    text-shadow: 0 1px 1px #fff;
}

.message.error {
    border: 1px solid #eeb7ba;
    background-color: #fae2e2;
    background-image: -o-linear-gradient(top,  #fae2e2,  #f2cacb);
    background-image: -ms-linear-gradient(top,  #fae2e2,  #f2cacb);
    background-image: -moz-linear-gradient(top,  #fae2e2,  #f2cacb);
    background-image: -webkit-gradient(linear, left top, left bottom, from(#fae2e2), to(#f2cacb));
    background-image: -webkit-linear-gradient(top,  #fae2e2,  #f2cacb);
    background-image: linear-gradient(top,  #fae2e2,  #f2cacb);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fae2e2', endColorstr='#f2cacb');
    color: #be4741;
    text-shadow: 0 1px 1px #fff;
}

.message.success {
    border: 1px solid #b8c97b;
    background-color: #e5edc4;
    background-image: -o-linear-gradient(top,  #e5edc4,  #d9e4ac);
    background-image: -ms-linear-gradient(top,  #e5edc4,  #d9e4ac);
    background-image: -moz-linear-gradient(top,  #e5edc4,  #d9e4ac);
    background-image: -webkit-gradient(linear, left top, left bottom, from(#e5edc4), to(#d9e4ac));
    background-image: -webkit-linear-gradient(top,  #e5edc4,  #d9e4ac);
    background-image: linear-gradient(top,  #e5edc4,  #d9e4ac);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#e5edc4', endColorstr='#d9e4ac');
    color: #3f7227;
    text-shadow: 0 1px 1px #fff;
}
于 2012-08-26T21:58:02.713 回答
0

代替您用来删除的按钮,另一个选项是在单击事件上创建一个淡出消息。

HTML:

<div id="msgAlert"> …session:messages goes here...</div>

JS:

<script type="text/javascript">
$('html').click(function() { $('#msgAlert').delay(5000).fadeOut('slow'); });

单击将在 5 秒后淡出会话消息。

于 2014-08-25T14:59:59.937 回答