【发布时间】:2014-09-06 10:48:11
【问题描述】:
我正在创建发布公告项目。
在这里我创建Session class 来管理session。
我的index.php
$bulletin = new Controller_Bulletin();
$bulletin->setParams(array_merge($_GET, $_POST));
$bulletin->execute('index'); // Execute index action
我的Controller_Bulletin.php
class Controller_Bulletin extends Controller_Base
{
...
public function index() // My index action
{
// Render the index html
$this->render('bulletin/index.php', get_defined_vars());
}
public function insert() // My insert action
{
...
}
...
}
我的Session class
class Session
{
public function __construct()
{
session_start();
}
...
}
我需要在每个动作中加载 Session 类。
示例:索引、插入等。
但是当我在每个动作中都加上$session = new Session(); 时。
导师说不好。
也许是因为我在每个动作中都重复了它。
Controller_Bulletin class中的示例
public function index()
{
$session = new Session();
...
}
public function insert()
{
$session = new Session();
...
}
我仍然不擅长 OOP。 有人可以告诉我应该在哪里调用会话对象吗? 如果我的问题还不清楚,请告诉我。
【问题讨论】: