私は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>
初めて 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 のビデオをほぼ一行一行コピーしましたが、まだ機能しません。私のセッションが破壊されているか何かのようです。何が起こっているのか教えてくれる人には永遠に感謝します。