【发布时间】:2017-02-02 13:33:45
【问题描述】:
在控制器中创建一个不是动作的函数是不好的做法吗?
例子:下面Controller中的createCookie函数
protected $translator;
protected $cookie;
public function __construct($translator, $cookie)
{
$this->translator = $translator;
$this->cookie = $cookie;
}
public function changeLanguageAction()
{
$language = $this->params()->fromRoute('lang', 'en');
$this->createCookie('xuage', $language, '/');
$this->getResponse()->getHeaders()->addHeader($this->cookie);
$this->redirect()->toRoute('home');
}
public function createCookie($name, $value, $path)
{
$this->cookie->setName($name);
$this->cookie->setValue($value);
$this->cookie->setPath($path);
}
【问题讨论】:
标签: php model-view-controller zend-framework2 zend-framework3