Zend Framework Action Assistant Flashmessenger usage, zendflashmessenger_php tutorial

Source: Internet
Author: User
Tags zend framework

Zend Framework Action Assistant Flashmessenger usage, Zendflashmessenger


This example describes the Zend Framework action Helper Flashmessenger usage. Share to everyone for your reference, as follows:

Flashmessenger is used to handle flash Messenger sessions; Flashmessenger is a magical assistant.

There is a scenario, after the user registration is successful, you need to display the user's name on the prompt page, if not through get delivery request, of course, you can also pass through the session

The name of the user to display. But Seesion's operations are complicated, and flash Messenger can be used to quickly implement this requirement.

The Flashmessenger helper allows you to pass a message that the user may need to see in the next request .

Flashmessenger also uses Zend_session_namespace to store messages for future or next requests to read, but relatively simple .

Flashmessenger Simple usage :

On the basis of the HELPER_DEMO1 project

New/helper_demo1/application/controllers/usercontroller.php

<?phpclass Usercontroller extends zend_controller_action{  protected $_flashmessenger = null;  Public function init ()  {    $this->_flashmessenger =    $this->_helper->gethelper (' Flashmessenger ') );    $this->initview ();  }  Public Function registeraction ()  {    $this->_flashmessenger->addmessage (' xxxxx,welcome! ');    $this->_helper->redirector (' regtips ');  }  Public Function regtipsaction ()  {    $this->view->messages = $this->_flashmessenger-> Getmessages ();  }}

New/helper_demo1/application/views/scripts/user/regtips.phtml

 
  Test<?phpvar_dump ($this->messages);? >

Visit http://www.localzend.com/helper_demo1/public/user/register
Jump to Http://www.localzend.com/helper_demo1/public/user/regtips

Flashmessager realize the source code as follows

<?php/** * Zend Framework * * LICENSE * * This source file was subject to the new BSD LICENSE that's bundled * with Thi s package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * HTTP://FRAMEWORK.ZEND.COM/LICENSE/NEW-BSD * If you do no T receive a copy of the license and is unable to * obtain it through the World-wide-web, please send a mail * to Licens e@zend.com so we can send you a copy immediately. * * @category Zend * @package zend_controller * @subpackage zend_controller_action_helper * @copyright Copyright (c) 200 5-2011 Zend Technologies USA Inc. (http://www.zend.com) * @license Http://framework.zend.com/license/new-bsd New BSD Li Cense *//** * @see zend_session */require_once ' zend/session.php ';/** * @see zend_controller_action_helper_abstract * * Require_once ' zend/controller/action/helper/abstract.php ';/** * Flash messenger-implement session-based Messages * * @u SES zend_controller_action_helper_abstract * @category Zend *@package Zend_controller * @subpackage zend_controller_action_helper * @copyright Copyright (c) 2005-2011 Zend Technologi  Es USA Inc. (http://www.zend.com) * @license HTTP://FRAMEWORK.ZEND.COM/LICENSE/NEW-BSD new BSD license * @version $Id: flashmessenger.php 23775 2011-03-01 17:25:24z Ralph $ */class Zend_controller_action_helper_flashmessenger extends Zend _controller_action_helper_abstract implements Iteratoraggregate, countable{/** * $_messages-messages from previous R  Equest * * @var array */static protected $_messages = Array ();  /** * $_session-zend_session Storage Object * * @var zend_session */static protected $_session = NULL; /** * $_messageadded-wether A message has been previously added * * @var Boolean */static protected $_messagea  dded = false; /** * $_namespace-instance namespace, default is ' default ' * * @var String */protected $_namespace = ' Default '  ; /** * __construct ()-Instance constructor, needed to get ITERAtors, etc * * @param string $namespace * @return void */Public function __construct () {if (!self::$_sessio      n instanceof zend_session_namespace) {self::$_session = new Zend_session_namespace ($this->getname ());        foreach (self::$_session as $namespace = $messages) {self::$_messages[$namespace] = $messages;      Unset (self::$_session->{$namespace}); }}}/** * Postdispatch ()-Runs after action was dispatched, in this * case, it was resetting the namespace in CA SE we have forwarded to a different * action, flashmessage'll be ' clean ' (default namespace) * * @return Zend_cont Roller_action_helper_flashmessenger provides a fluent interface */Public function Postdispatch () {$this->reset    Namespace ();  return $this; }/** * Setnamespace ()-Change the namespace messages is added to, useful for * per action controller messaging bet Ween Requests * * @param string $namespace * @return Zend_controller_action_hElper_flashmessenger provides a fluent interface */Public function setnamespace ($namespace = ' default ') {$this-&G    T;_namespace = $namespace;  return $this; }/** * Resetnamespace ()-Reset the namespace to the default * * @return Zend_controller_action_helper_flashmessen    GER provides a fluent interface */Public function resetnamespace () {$this->setnamespace ();  return $this; }/** * AddMessage ()-ADD a message to Flash message * * @param string $message * @return zend_controller_action _helper_flashmessenger provides a fluent interface */Public function addmessage ($message) {if (Self::$_messageadd    ed = = = False) {Self::$_session->setexpirationhops (1, NULL, TRUE); } if (!is_array (self::$_session->{$this->_namespace})) {self::$_session->{$this->_namespace} = Array (    );    } self::$_session->{$this->_namespace}[] = $message;  return $this; }/** * Hasmessages ()-Wether a specific namespace has MEssages * * @return Boolean */Public function hasmessages () {return isset (self::$_messages[$this->_namespa  CE]); }/** * Getmessages ()-Get messages from a specific namespace * * @return array */Public function getmessages (    {if ($this->hasmessages ()) {return self::$_messages[$this->_namespace];  } return Array (); }/** * Clear All messages from the previous request & current Namespace * * @return Boolean True if messages W Ere cleared, False if none existed */Public function clearmessages () {if ($this->hasmessages ()) {unset (s      elf::$_messages[$this->_namespace]);    return true;  } return false;   }/** * Hascurrentmessages ()-Check to see if messages has been added to current * namespace within this request * * @return Boolean */Public function hascurrentmessages () {return isset (self::$_session->{$this->_namesp  ACE}); }/** * Getcurrentmessages ()-Get messages that has Been added to the current * namespace within this request * * @return Array */Public function Getcurrentmessage    S () {if ($this->hascurrentmessages ()) {return self::$_session->{$this->_namespace};  } return Array (); }/** * Clear messages from the current request & current Namespace * * @return Boolean */Public Function C      Learcurrentmessages () {if ($this->hascurrentmessages ()) {unset (self::$_session->{$this->_namespace});    return true;  } return false; }/** * Getiterator ()-Complete the Iteratoraggregate interface, for iterating * * @return Arrayobject */publi    C function Getiterator () {if ($this->hasmessages ()) {return new Arrayobject ($this->getmessages ());  } return new Arrayobject (); }/** * COUNT ()-Complete the countable interface * * @return int */Public Function count () {if ($this-&G    T;hasmessages ()) {return count ($this->getmessages ());  }  return 0; }/** * Strategy pattern:proxy to AddMessage () * * @param string $message * @return void */Public function D  Irect ($message) {return $this->addmessage ($message); }}

More interested in Zend related content readers can view the topic: "Zend framework of the introductory tutorial", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Tutorial", "PHP object-oriented Programming introduction tutorial "," Introduction to Php+mysql Database Operation "and" PHP common database Operation Skills Summary "

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • Controller usage Analysis of MVC Framework for Zend Framework Tutorial
    • Zend Framework Tutorial's routing function zend_controller_router detailed
    • Zend Framework Tutorial Zend_controller_plugin plugin Usage
    • Package Zend_controller_response Example of response object for Zend Framework tutorial
    • Package Zend_controller_request example of request object for Zend Framework tutorial
    • Zend Framework Tutorial Action base class Zend_controller_action detailed
    • Zend Framework Tutorial Distributor Zend_controller_dispatcher Usage
    • Zend Framework Tutorial Front Controller Zend_controller_front Usage
    • Zend Framework Action Assistant Redirector usage examples
    • Zend Framework Action Helper URL usage detailed
    • Zend Framework Action Helper JSON usage example analysis
    • Examples of resource autoloading usages of the Zend framework tutorial

http://www.bkjia.com/PHPjc/1106900.html www.bkjia.com true http://www.bkjia.com/PHPjc/1106900.html techarticle Zend Framework Action Assistant Flashmessenger usage, Zendflashmessenger This example describes Zend Framework action Assistant Flashmessenger usage. Share to everyone for your reference, specific ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.