【问题标题】:Zend Sessions Problem (beginner)Zend 会话问题(初学者)
【发布时间】:2009-06-01 18:52:17
【问题描述】:

我正在自学 Zend am,但在使用我的会话调用 View Helper 操作时遇到问题。

我的控制器:

<?php
class SessionController extends Zend_Controller_Action
{
    protected $session;
    public function init() //Like a constructor
    {
        $this->_helper->viewRenderer->setNoRender(); // Will not automatically go to views/Session
        $this->_helper->getHelper('layout')->disableLayout(); // Will not load the layout
    }       

    public function preDispatch() //Invokes code before rendering.  Good for sessions/cookies etc.
    {
        $this->session = new Zend_Session_Namespace(); //Create session
        if(!$this->session->__isset('view'))
        {
            $this->session->view = $this->view; //if the session doesn't exist, make it's view default
        }

    }
    public function printthingAction()
    {
        echo $this->session->view->tabbedbox($this->getRequest()->getParam('textme'));
    }
}
?>

我的视图助手

<?php
class App_View_Helper_Tabbedbox extends Zend_View_Helper_Abstract
{
    public $wordsauce = "";
    public function tabbedbox($message = "")
    {
        $this->wordsauce .= $message;
        return '<p>' . $this->wordsauce . "</p>";
    }
}
?>

我的看法:

<p>I GOT TO THE INDEX VIEW</p>

<input id='textme' type='input'/>
<input id='theButton' type='submit'/>

<div id="putstuffin"></div>

<script type="text/javascript">
$(function()
{
    $("#theButton").click(function()
    {
        $.post(
        "session/printthing",
        {'textme' : $("#textme").val()},
        function(response)
        {
            $("#putstuffin").append(response);
        });
    });
});

</script>

当我第一次点击按钮时,它会起作用,并且会按预期添加我的单词。但是,每次之后,它都会给我这个错误消息:

警告:call_user_func_array() [function.call-user-func-array]:第一个参数应该是一个有效的回调,'__PHP_Incomplete_Class::tabbedbox' 在 C:\xampp\htdocs\BC 中给出\library\Zend\View\Abstract.php 第 341 行

我几乎一行一行地复制了 Zendcasts.com 的视频,但它仍然无法正常工作。好像我的会话被破坏了。我将永远感激任何能告诉我发生了什么的人。

【问题讨论】:

    标签: zend-framework session zend-view zend-session


    【解决方案1】:

    当您在会话中存储一个对象时,您实际上是在存储它的序列化表示。出现 __PHP_Incomplete_Class::tabbedbox 是因为在后续请求中,PHP 忘记了 App_View_Helper_Tabbedbox 是什么。

    解决方案:确保在调用 Zend_Session::start() 之前包含 App_View_Helper_Tabbedbox 类文件。

    而且,最好的方法是把它放在你的应用程序的开头:

    require_once 'Zend/Loader.php';
    Zend_Loader::registerAutoload();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-04
      • 2020-11-23
      • 2015-03-16
      • 2012-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多