2012-08-15 62 views
1

在PyroCMS中,我使用session:messages标记向用户显示消息。这很好,但我想为每条消息添加一个关闭按钮,这需要在每条消息中放置一个范围。例如:会话的自定义输出:消息?

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

每个消息被包裹在一个div,这是通过设置session:messages标记的属性赋予一个类。没有内置的方式来指定输出。我如何覆盖session.php中的messages()函数,添加一个新的属性来追加这个关闭按钮?

到目前为止,我曾尝试:

  1. 复制系统/ CMS /插件/ session.php文件为*插件/ shared_addons /插件/ session.php文件*和修改messages()功能。使用核心功能,而不是像我所希望的那样插入新插件。

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

回答

3

这不是可以延长某些东西都是在核心(e.g. libraries and helpers) - 我觉得适用于插件了。

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

在一个典型的网站,我想不出,你会永远需要一些警告的情况不同的方式显示给他人(不是依赖于过程的结果,你可以在CSS使用类做不同的颜色等名称)。

提供你使用Git(你克隆或分叉的official PyroCMS repository并提出自己的分支),你会与未来的更新绝对没问题 - 如果在未来的版本中会插件改变,任何改变都会只是自动合并到您的代码中,或者如果Git无法解决它,它会向您显示差异并提示您手动修复它。

注意 - 有一对夫妇为基础的管理界面上这一特定问题的其他解决方案(你可能已经注意到了闪光灯的消息有可关闭)。

您可以创建一个部分 - 可以包含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>/系统/ CMS /模块/所见即所得/ JS /所见即所得。JS

// Add the close link to all alert boxes 
$('.alert').livequery(function(){ 
    $(this).prepend('<a href="#" class="close">x</a>'); 
}); 
+0

我使用liveQuery渐进增强方法来确保没有使用Javascript的人(可能还有一个人)没有看到关闭按钮。这是一个关于部分接受PHP的好建议!我会在不久的将来利用这一点。 – 2012-08-16 12:35:21

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; 
} 
+2

正确!您可以更改正在使用的类,但不能更改整个HTML。为此,您可以使用PHP或自己的标签进行自定义。 – 2012-09-06 16:12:13

0

而不是使用删除的按钮,另一种选择是woul d是在点击事件时创建淡出消息。

HTML:

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

JS:

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

有一个点击后5秒将淡出会话消息。