在php中设置并获取全局变量(ZendFramework)

Amr*_*ngh 2 php zend-framework

我在PHP中使用ZendFramework,我想设置并获取一个变量作为全局变量.IE我把它设置在Zend Controller的类中,并在类中访问它的任何动作.

例如:

<?php

class SubscriptionController extends Zend_Controller_Action
{
    private $EMAIL = false;
    private $USERNAME = false;
Run Code Online (Sandbox Code Playgroud)

首先,我通过ajax调用验证电子邮件地址

    public function checkusernameAction()
    {
        $email = //query to find email;     
        if($email){
        $EMAIL = true;
        }else{
        $EMAIL = false;
        }
    }
Run Code Online (Sandbox Code Playgroud)

然后我想再次使用ajax调用基于私有变量订阅用户

    public function subscribeAction
    {
      if($EMAIL == true)
       {
         //some stuff 
       }        
    }
Run Code Online (Sandbox Code Playgroud)

我通过$ this-> EMAIL得到私有var,但无法访问它

Sha*_*ngh 6

您可以使用Zend_Registry在整个应用程序中使用该变量.

您可以设置这样的变量

Zend_Registry::set('email', $EMAIL);
Run Code Online (Sandbox Code Playgroud)

以后可以这样得到它

$email= Zend_Registry::get('email');
Run Code Online (Sandbox Code Playgroud)