我正在处理一个自定义模块,我在其中输入值,如果它在db中匹配,它会重定向到主页,并在主页上显示为blah Blah,或者如果没有进入登录页面。 我尝试了以下公共函数,条件为
if(count($alldata)==1) {
Mage::getSingleton('helloworld/helloworld')->addSuccess('my message goes here');
$this->_redirect('home');
}else {
$this->_redirect('customer/account');
}
但是这会给出一个预先请求错误。
这是我在控制器中添加的全部代码
public function loginnAction()
{
if($this->getRequest()->getParams()) {
$param = $this->getRequest()->getParams();
$username = $param['fname'];
$mobile = $param['mobileno'];
$connectionresource = Mage::getSingleton('core/resource');
$readconnection = $connectionresource->getConnection('core_read');
$table = $connectionresource->getTableName('helloworld/helloworld');
$allrecord = $readconnection->select()->from(array('helloworld'=>$table))->where('helloworld.mobileno=?', $mobile)
->where('helloworld.firstname=?', $username);
$alldata =$readconnection->fetchAll($allrecord);
if(count($alldata)==1) {
Mage::getSingleton('helloworld/helloworld')->addSuccess('my message goes here');
$this->_redirect('home');
}else {
$this->_redirect('customer/account');
}
}
}
这不是正确的格式吗?还是有更多我应该做的改变?
更新了代码
public function loginnAction()
{
if($this->getRequest()->getParams()) {
$param = $this->getRequest()->getParams();
$username = $param['fname'];
$mobile = $param['mobileno'];
$connectionresource = Mage::getSingleton('core/resource');
$readconnection = $connectionresource->getConnection('core_read');
$table = $connectionresource->getTableName('helloworld/helloworld');
$allrecord = $readconnection->select()->from(array('helloworld'=>$table))->where('helloworld.mobileno=?', $mobile)
->where('helloworld.firstname=?', $username);
$alldata =$readconnection->fetchAll($allrecord);
if(count($alldata)==1) {
Mage::getSingleton('core/session')->addSuccess('my message goes here');
$this->_redirect('home');
}else {
$this->_redirect('customer/account');
}
}
}
答案 0 :(得分:7)
使用Magento全局消息传递系统:
<强>成功强>
Mage::getSingleton('core/session')->addSuccess('my message goes here');
错误
Mage::getSingleton('core/session')->addError('my message goes here');
警告强>
Mage::getSingleton('adminhtml/session')->addWarning('my message goes here');
如果您的模板支持,该消息将显示在下一个呈现的页面中。
重定向或重新加载用户以显示消息。