dthp96899 2011-11-01 05:21
浏览 38
已采纳

使用Zend Framework在我的控制器中获取“致命错误:无法访问空属性”

This is the bit of code, it's a base class for my controller that initializes all common values. The file is in my models folder if that makes a difference. The weird thing is it works locally in MAMP where I'm developing, but not on the server. I'm thinking it may be a configuration issue?

<?php
Zend_Loader::loadClass('Zend_Controller_Action');

class BaseController extends Zend_Controller_Action
{
    protected $auth;
    protected $current_user;
    protected $db;

    protected function initialize_values()
    {
        $auth = Zend_Auth::getInstance();
        if($auth->hasIdentity())
        {
            $this->$current_user = $auth->getIdentity();
            $this->view->user = $this->$current_user;
        }

        $this->db = Zend_Registry::get('dbAdapter');

        $this->view->controller_name = $this->_request->getControllerName();
        $this->view->view_name = $this->_request->getActionName();
    }
}

I get it on the line that is first in the if statement

$this->$current_user = $auth->getIdentity();

I understood this error to mean it was trying to access a property or method that doesn't exist. In this case I know that exists

  • 写回答

2条回答 默认 最新

  • dongmopu6734 2011-11-01 07:57
    关注

    Instead of $this->$current_user, shouldn't you use $this->current_user

    $current_user is null in your case, hence the error.

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

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下