我有一个自定义页面在magento.My条件是“如果用户没有登录,所以在保存任何更改之前,我将用户重定向到登录页面,我想在登录后重定向到我的自定义页面上的用户”。我正在使用以下代码,它没有重定向我的自定义页面后登录。
Mage::app('default');
if( !Mage::getSingleton( 'customer/session' )->isLoggedIn() ){
$session = Mage::getSingleton( 'customer/session' );
$session->setBeforeAuthUrl('http://'.$_SERVER['HTTP_HOST'].'/custom.html');
header("Location: /customer/account/login");
}它在登录页面上重定向我。如果我使用下面的代码而不是header,它不会将我重定向到登录页面。
Mage::app()->getResponse()->setRedirect(Mage::getUrl("customer/account/login")); 或
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));1)我在同一个域名上。
2) [系统]>[配置]>[客户配置]部分[登录选项] -> [登录后将客户重定向到账户仪表板]设置为否。
我想在重定向到登录页面之前设置返回的url。因此,在登录后,它会将用户重定向到返回的url页面。我的自定义页面在magento之外(&M)。
以下是我的自定义页面代码。
$mageFilename = 'app/Mage.php';
require_once( $mageFilename );
umask(0);
Mage::app();
if( !Mage::getSingleton( 'customer/session' )->isLoggedIn() ){
$session = Mage::getSingleton( 'customer/session' );
$session->setBeforeAuthUrl('http://'.$_SERVER['HTTP_HOST'].'/full-custom.php?sid=8');
header("Location: /customer/account/login");
//Mage::app()->getResponse()->setRedirect(Mage::getUrl("customer/account/login"));
//Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
}请帮帮我!!
发布于 2012-10-10 17:15:56
尝试使用以下代码进行重定向
if( !Mage::getSingleton( 'customer/session' )->isLoggedIn() )
{
$this->_redirect('page_url');
}在Magento中,_redirect是页面重定向的属性。应用您的自定义页面url,而不是使用page_url。
发布于 2013-11-06 19:22:09
我也遇到过类似的问题,但我使用了不同的解决方案。在我的场景中,Magento将用户重定向到最后一个页面,他在最后一次登录时处于打开状态。
起初它很混乱,因为即使在设置了管理>系统>配置>客户配置>登录选项>将客户重定向到帐户仪表板之后,登录到NO之后,我仍然被重定向到仪表板。
最后,我意识到这正是我最近注销后访问的最后一个页面。
无论如何,我希望Magento在登录后总是将用户重定向到他当前所在的最后一个页面。
我想避免安装任何扩展,或者创建自己的附加扩展(这包括重写AccountController)。所以我简单地通过本地重写Magento/Customer/Model/Session.php解决了这个问题,其中我在login方法中添加了$this->unsBeforeAuthUrl();(在成功进行身份验证之后)。
public function login($username, $password)
{
/** @var $customer Mage_Customer_Model_Customer */
$customer = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
if ($customer->authenticate($username, $password)) {
$this->unsBeforeAuthUrl(); // <-- my addition
$this->setCustomerAsLoggedIn($customer);
$this->renewSession();
return true;
}
return false;
}多亏了这一点,现在每次用户登录时,before_auth_url都会被清除,这迫使magento将用户重定向到存储在referer参数中的url。
我必须向我的mini.login.phtml表单添加referer参数。是这样做的。
首先,在template/customer/form/mini.login.phtml的顶部添加:
<?php
$params = Mage::helper('customer')->getLoginUrlParams();
$ref = isset($params[Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME])?$params[Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME]:false;
?>然后在I中的某个位置添加:
<?php if ($ref): ?>
<input type="hidden" name="<?php echo Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME ?>" value="<?php echo $ref ?>"/>
<?php endif; ?>现在它以我想要的方式工作(至少现在,我今天创建了这个)。当我遇到这个解决方案的一些问题时,我会尝试添加一些评论。
我不确定它是否是完美的解决方案(因为它需要添加这个引用跟踪)-也许Magento在内部将最后一个url存储在其他地方,并可以从会话中读取它。
发布于 2013-10-09 12:43:11
优先:
进入admin > System > Configuration > customer configuration > Login Options > set No设置为"Redirect Customer to Account Dashboard after Login in“
然后是:
打开\app\code\core\Mage\Customer\controllers\AccountController.php
看看187行。Mage::helper('customer')->getAccountUrl()是指向客户仪表板的重定向url。将其更改为所需的url。
也就是说,您可以更改:
$session->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl());至
$session->setBeforeAuthUrl(Mage::getBaseUrl());成功登录后,会将客户重定向到主页
https://stackoverflow.com/questions/12815773
复制相似问题