我想将客户重定向到登录页面,如果他们没有从网站上的任何页面登录。我正在尝试将访问子域的权限限制为特定的客户组,并且我的其余代码可以正常工作。
如果我在home.tpl上使用以下代码,它可以工作
if (!$logged) {
$this->redirect($this->url->link('account/login', '', 'SSL'));
}但是如果我把它放在头中(这样它就会对每个页面做出反应),我会得到一个重定向循环,因为它会尝试将实际的登录页面重定向到它自己。
有没有一种方法可以正确地说:
if ($this->url->link != 'account/login') {
$this->redirect($this->url->link('account/login', '', 'SSL'));
}提前感谢您的帮助。
哑光
发布于 2013-12-04 09:06:48
假设你想要检查商店是否也是子域商店,你应该使用如下代码
// Check store ID against subdomain store id value
if($this->config->get('config_store_id') == 123) {
// Check customer isn't logged in
if(!$this->customer->isLogged()) {
// Redirect if route isn't account/login
if(empty($this->request->get['route']) || $this->request->get['route'] != 'account/login') {
$this->redirect($this->url->link('account/login', '', 'SSL'));
}
}
}发布于 2013-12-04 17:46:47
另一种可能性是创建类似preAction的维护模式。我已经使用过一次,我认为这比在视图模板中实现它要干净得多(所以它遵循MVC模式-逻辑在控制器中完成,视图只用于呈现数据和收集用户的输入)。
创建一个类catalog/controller/common/login.php
class ControllerCommonLogin extends Controller {
public function index() {
if($this->config->get('config_store_id') == 1) { // if desired store, continue checking
if(!$this->customer->isLogged()) { // Check user isn't logged in
if(empty($this->request->get['route']) || $this->request->get['route'] != 'account/login') { // Redirect if route isn't account/login
$this->redirect($this->url->link('account/login', '', 'SSL'));
}
}
}
}
}然后打开index.php (前端一),找到一行:
// Maintenance Mode
$controller->addPreAction(new Action('common/maintenance'));和后面的添加以下内容:
// Login needed pre-action
$controller->addPreAction(new Action('common/login'));你应该做完了。
发布于 2013-12-04 02:16:36
您需要添加如下条件:
if($this->config->get('config_store_id') == 1) { //Add your subdomain store id, if you want to limit the condition for a subdomain.
if( (!isset($this->request->get['route']) || $this->request->get['route'] != 'account/login' ) && (!$this->customer->isLogged()) ){
$this->redirect($this->url->link('account/login', '', 'SSL'));
}
}$this->request->get['route'] -这将为您提供当前页面路径。
https://stackoverflow.com/questions/20357962
复制相似问题