Zend 会话问题(初学者)

发布于 2024-07-22 11:18:35 字数 2180 浏览 7 评论 0 原文

我正在自学 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 视频,但它仍然无法正常工作。 看来我的会话被破坏了或者发生了什么。 我将永远感激任何能告诉我发生了什么事的人。

I'm teaching myself Zend am and having a problem with using my session to call a View Helper action.

My controller:

<?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'));
    }
}
?>

My view helper

<?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>";
    }
}
?>

My view:

<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>

The first time I click on theButton, it works, and appends my word like it's supposed to. For every time after, though, it gives me this error message:

Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, '__PHP_Incomplete_Class::tabbedbox' was given in C:\xampp\htdocs\BC\library\Zend\View\Abstract.php on line 341

I copied the Zendcasts.com video almost line for line, and it's still not working. It seems like my session is getting destroyed or something. I would be forever grateful to anyone who could tell me what's happening.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狼性发作 2024-07-29 11:18:35

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

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

而且,最好的方法是将其放在应用程序的开头:

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

When you store an object in the session, you're really storing a serialized representation of it. The __PHP_Incomplete_Class::tabbedbox occurs because, on subsequent requests, PHP has forgotten what an App_View_Helper_Tabbedbox is.

The solution: make sure you include the App_View_Helper_Tabbedbox class file before Zend_Session::start() is called.

And, the best way to do that is to place this at the opening of your app:

require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文