在 CakePHP 中更改语言
Change language in CakePHP
我正在尝试在我的 CakePHP 应用程序中实现语言更改按钮。我遵循了食谱 (http://book.cakephp.org/2.0/en/core-libraries/internationalization-and-localization.html),现在我可以在用户登录后更改语言。
我的语言按钮链接到我自己的 LanguagesController
中的操作,如下所示:
public function sk() {
$this->Session->write('Config.language', 'svk');
$this->redirect($this->referer());
}
public function en() {
$this->Session->write('Config.language', 'eng');
$this->redirect($this->referer());
}
然后在 AppController beforeFilter()
函数中我有以下内容:
if ($this->Session->check('Config.language')) {
Configure::write('Config.language', $this->Session->read('Config.language'));
}
但是,这只在用户登录时有效,我想让未登录的用户也可以更改应用程序语言。我试过这个:
public function en() {
Configure::write('Config.language', 'eng');
$this->redirect($this->referer());
}
但它对我不起作用。
另一件事 - 我想将应用程序的默认语言更改为斯洛伐克语,但是当我输入时:
Configure::write('Config.language', 'svk');
到上面提到的app/Config/bootstrap.php
none完全没有用。
提前感谢大家的帮助:)
Cake php 提供了一种无需登录系统即可执行功能的非常好的方式。即 $this->Auth->allow()
在 AppController
.
所以
在应用程序控制器中,您会在某处看到此行 $this->Auth->allow()
。在那只是给那些将改变语言的动作名称。该功能也无需用户登录即可开始工作。如果你没有在你的 AppController
中找到这一行,那么你也可以写它。
我正在尝试在我的 CakePHP 应用程序中实现语言更改按钮。我遵循了食谱 (http://book.cakephp.org/2.0/en/core-libraries/internationalization-and-localization.html),现在我可以在用户登录后更改语言。
我的语言按钮链接到我自己的 LanguagesController
中的操作,如下所示:
public function sk() {
$this->Session->write('Config.language', 'svk');
$this->redirect($this->referer());
}
public function en() {
$this->Session->write('Config.language', 'eng');
$this->redirect($this->referer());
}
然后在 AppController beforeFilter()
函数中我有以下内容:
if ($this->Session->check('Config.language')) {
Configure::write('Config.language', $this->Session->read('Config.language'));
}
但是,这只在用户登录时有效,我想让未登录的用户也可以更改应用程序语言。我试过这个:
public function en() {
Configure::write('Config.language', 'eng');
$this->redirect($this->referer());
}
但它对我不起作用。
另一件事 - 我想将应用程序的默认语言更改为斯洛伐克语,但是当我输入时:
Configure::write('Config.language', 'svk');
到上面提到的app/Config/bootstrap.php
none完全没有用。
提前感谢大家的帮助:)
Cake php 提供了一种无需登录系统即可执行功能的非常好的方式。即 $this->Auth->allow()
在 AppController
.
所以
在应用程序控制器中,您会在某处看到此行 $this->Auth->allow()
。在那只是给那些将改变语言的动作名称。该功能也无需用户登录即可开始工作。如果你没有在你的 AppController
中找到这一行,那么你也可以写它。