wha*_*ore 1 cookies symfony1 model
是否可以从模型层设置(或检索)cookie?
假设模型层用于"业务逻辑",我需要的逻辑需要与请求和响应进行一些交互.
我建议您在模型中处理和存储您的cookie值:
class ModelTable
{
protected $cookie = null;
public function getCookie()
{
return $this->cookie;
}
public function setCookie($value)
{
$this->cookie = $value;
}
}
Run Code Online (Sandbox Code Playgroud)
并使用postExecute操作来设置cookie:
class yourActions extends sfActions
{
public function executeIndex(sfWebRequest $request)
{
ModelTable::getInstance()->setCookie('bla');
}
public function postExecute()
{
$cookie = ModelTable::getInstance()->getCookie();
$this->getResponse()->setCookie('name', $cookie, time() + 24 * 3600);
}
}
Run Code Online (Sandbox Code Playgroud)
坚持MVC模型总是更好:控制器调用信息模型并构建响应,而不是反过来.
| 归档时间: |
|
| 查看次数: |
1965 次 |
| 最近记录: |