dongque5529 2014-07-16 22:11
浏览 30
已采纳

将变量从一种方法传递给另一种方法[关闭]

I'm having trouble passing a variable from one method to another, I'm trying as follows, but failed

ddsd

    public function hacerloginAction(){    
    //Obtener parámetros
    $v_c_request    = $this->getRequest();
    $a_params       = $v_c_request->getParams();


    $v_c_url                = Zend_Registry::get('base_action')."login/hacerlogin";
    $this->view->v_c_url    = $v_c_url;

    //Realizar autentificación OpenId - Parte 1: conectar_openid

        //p_c_parametros 
        $_SERVER['PHP_SELF'] = str_replace("/p_c_parametros", "", dirname($_SERVER['PHP_SELF']));
        //Si 'a_params["p_c_parametros"]' tiene valores se asignan a una variable de sesion
        if( isset($a_params["p_c_parametros"]) && $a_params["p_c_parametros"] != null){
            $_SESSION['p_c_parametros'] = $a_params["p_c_parametros"];
        }

        //Se obtienen el parametro de 'p_openid' hya.com.mx
        $p_openid = str_replace("|","/",$a_params["p_openid"]);
        $this->obj_openidlog->conectar_openid($p_openid);

    //Render a la página de inicio.
    $this->render("formalogin");
}

ds

  • 写回答

6条回答 默认 最新

  • douyan1613 2014-07-16 22:26
    关注

    I managed to get output of "success" quite simply, the following code will produce the desired output:

    class myclass{
        public $global;
        public function method_one(){
            $this->global = "succes";
        }
    
        public function method_two(){
            return $this->global;
        }
    }
    
    $Class = new myclass();
    
    $Class->method_one();
    echo $Class->method_two();
    

    As global is set to blank by default, you will have to call method_one(); to give the internal variable a value. Only then you would beable to produce an echo.

    Otherwise, the following:

    $Class = new myclass();
    
    
    var_dump($Class->method_two());
    

    produces

    NULL


    On a side note. I'd recommend avoiding the use of reserved PHP words such as global as it could create alot of confusion later on in the development Use of Global scope in PHP


    With your updated code

    The reason you are not getting the expected validations is this little line here:

     header("Location: http://hyapresenta.com/sv3/public/login/obtener");
    

    since you are calling your first method to set the variable.. You are also causing a page redirect, which is resetting all your changes prior to this (this is because your defaults are loaded on pageload), You could look into using sessions to keep your changes past page refreshes. Only downside is that it'll require a drastic structure change

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题,请各位专家解答!
  • ¥15 如何批量抓取网站信息
  • ¥15 Spring Boot离线人脸识别
  • ¥15 NRF24L01能发送但是不能接收
  • ¥15 想问一下这种情况怎么解决呢(关键词-file)
  • ¥15 python Flassk 模块部署 服务器时报错
  • ¥15 Opencv(C++)异常
  • ¥15 VScode上配置C语言环境
  • ¥15 汇编语言没有主程序吗?
  • ¥15 这个函数为什么会爆内存