2009-06-01 255 views
1

我在教自己Zend,并在使用我的会话调用View Helper操作时遇到问题。Zend Sessions问题(初学者)

我的控制器:

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

我第一次点击theButton,它的工作原理,并追加像我的话它应该。但是,对于每一次后,它给了我这个错误信息:

警告: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视频几乎行为线,它仍然无法正常工作。好像我的会话正在被破坏或者什么东西。我会永远感谢任何能告诉我发生了什么的人。

回答

2

当你在会话中存储一个对象时,你真的存储了一个序列化表示它。发生__PHP_Incomplete_Class :: tabbedbox是因为在随后的请求中,PHP已经忘记了App_View_Helper_Tabbedbox是什么。

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

而且,要做到这一点的最好办法是把这个在您的应用程序的开放:

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

这就是它!谢谢。 – Ethan 2009-06-17 18:59:10