使用Zend Framework FlashMessenger和jQuery UI状态类 [英] Working with Zend Framework FlashMessenger and jQuery UI state classes

查看:128
本文介绍了使用Zend Framework FlashMessenger和jQuery UI状态类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用jQuery UI的Zend Framework应用程序。

I have a Zend Framework application that is making use of jQuery UI.

在我的控制器中,我使用FlashMessenger帮助设置错误/成功消息,

In my controllers, I am setting error/success messages with the FlashMessenger helper like this:

// ExampleController.php
$this->_helper->FlashMessenger('Sorry, could not complete your request.');

在我的布局中,我使用 Noumenal FlashMessenger View Helper

In my layout, I am displaying the messages by using the Noumenal FlashMessenger View Helper

// layout.phtml
<?php echo $this->flashMessenger(); ?>

我想使用我的 jQuery UI主题的CSS样式来样式我的错误消息:

I want to make use of my jQuery UI theme's CSS styles to style my error messages like this:

<div class="ui-state-error ui-corner-all"> 
    <p><span class="ui-icon ui-icon-alert"></span> 
    <strong>Alert:</strong> Sample ui-state-error style.</p>
</div>

...但是View Helper正在做所有的工作,所以我不能更改类我怎么想。所以在走下死胡同的路线之前,我想我会问社区。这是我的问题:

...but the View Helper is doing all the work, so I can't change the classes how I want to. So before going down a dead end route, I thought I'd ask the community. Here are my questions:


  1. 如何使用Zend Framework FlashMessenger,以便我可以根据状态设置不同的消息)

  2. 如何从FlashMessenger获取邮件并将其显示在一个地方,而不必在所有控制器中创建重复的代码?

  3. 如何为每个不同的消息状态输出不同的类?例如:
    'error'=>'ui-state-error','info'=>'ui-state-highlight'

  1. How can I use the Zend Framework FlashMessenger so that I can set different messages depending on the state (error/success)?
  2. How can I get the messages from the FlashMessenger and display them in a single place without having to create duplicate code in all of my controllers?
  3. How can I output a different class for each of the different message states? For example: 'error'=>'ui-state-error', 'info'=>'ui-state-highlight', etc.


推荐答案

写了 Noumenal FlashMessenger View Helper 我应该能够帮助。 : - )

Having written the Noumenal FlashMessenger View Helper I should be able to help. :-)

要回答您的问题:

您可以设置不同的消息级别,例如 c:错误警告等,通过传递一个数组到FlashMessenger Action Helper,而不是一个简单的字符串:

You can set different message levels, e.g. error, warning etc, by passing an array to the FlashMessenger Action Helper rather than a simple string:

// ExampleController.php
$this->_helper->FlashMessenger(
     array('error'=>'Sorry, could not complete your request.')
);

视图助手旨在识别此问题。

The view helper is designed to recognise this.

在布局中输出FlashMessage时,可以传递可选参数以指定默认消息级别(

When outputting FlashMessages in your layout, there are optional parameters that you can pass to specify the default message level (which is warning by default) and a template for your message.

根据不同的邮件级别调整您的代码段,以获得所需的结果。在您的布局中进行以下调用:

Adapting your code snippet to account for differing message levels you could achieve the desired result by making the following call in your layout:

// layout.phtml
$template = '<div class="ui-state-error ui-corner-all"> 
    <p class="%s"><span class="ui-icon ui-icon-alert"></span> 
    <span class="flash-message">%s</span></p>
</div>';
echo $this->flashMessenger('error', $template);

(你可能会发现更好地将模板设置为视图变量,比如说你的引导。 )

(You may find it better to set the template as a view variable in, say, your bootstrap.)

这样,视图助手会根据需要为您构建相应格式的flash消息。

Doing this the view helper will construct the appropriately formatted flash messages for you as you wish.

使用CSS会有足够的空间来适当地设置消息的样式。例如:

Using CSS there would be plenty of room to style the messages appropriately. For example:

.alert {
    color: red;
}

.alert .flash-message:before {
    content: "<strong>Alert</strong> ";
}

.notice {
   color:yellow;
}

.notice .flash-message:before {
    content: "<strong>Notice</strong> ";
}    

我让你即兴...

我写了一份指南Zend Framework FlashMessenger和我的博客上的视图助手。也许给一个读。此外,请,它将帮助我知道我需要什么改善。

I wrote a guide to Zend Framework FlashMessenger and the view helper on my blog. Perhaps give that a read. Also please do email me to let me know your difficulties -- it will help me know what I need to improve.

我希望能有所帮助。

这篇关于使用Zend Framework FlashMessenger和jQuery UI状态类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆