2009-06-01 170 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