我指的是如何使用与Zend Framework的会话的文档: http://framework.zend.com/manual/1.12/en/learning.multiuser.sessions.html
此时我已开始使用骨架应用程序,我修改的唯一内容是控制器。我发布了应用程序模块控制器的代码:
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController
{
public function indexAction()
{
$mysession = new Zend_Session_Namespace('mysession');
if (!isset($mysession->counter)) {
$mysession->counter = 1000;
} else {
$mysession->counter++;
}
if ($mysession->counter > 1999) {
unset($mysession->counter);
}
return new ViewModel();
}
}
我去路线时看到的第一件事是:
Fatal error: Class 'Application\Controller\Zend_Session_Namespace' not found in C:\Program Files (x86)\Zend\Apache2\htdocs\zf2-sessioncounter\module\Application\src\Application\Controller\IndexController.php on line 19
所以我认为这与使用Zend_Session_Namespace有关,或者可能是因为我的应用程序没有为Zend_Application设置?这会是一个正确的地方放置会话PHP吗?
答案 0 :(得分:2)
Zend_Session_Namespace
实际上是ZF1的一个组件 - 由于许多原因(不使用正确的命名空间机制是最重要的),因此不应该在ZF2应用程序中使用它。
use Zend\Session\Container;
// ...
$mysession = new Container('mysession');