【发布时间】:2014-04-21 14:41:51
【问题描述】:
您好,我在查看页面上有一个按钮,我必须检查谁在点击该按钮我们的网站上有不同类型的用户,所以我们不想允许我们网站的特定类型的用户单击该按钮或进行任何更改,以便我们在单击时检查谁在单击按钮是我们想要或不想要的用户,因此我在单击按钮时检查会话ID . 那么现在我想要的是,如果我们不希望的用户单击该按钮,那么他们应该重定向到带有会话消息的感谢页面。 我知道如何从 cakephp 控制器显示会话消息的方法我使用了这个:
**$sending = SITE_URL."thanks";
$this->Session->setFlash(__("Sorry! You are unauthorized user. Contact us at help@example.com", true), 'default', array('class' => 'notclass'));
echo "<script type='text/javascript'> window.location.href='".$sending."';</script>";
die;**
但是当我在我的条件之后在 .ctp 文件中尝试相同的逻辑时
if($this->Session->read('Auth.User.id')!='' && $this->Session->read('Auth.User.role_id')=='2'){
<th></br><span style="font-family: 'proximanova semibold',Ubuntu;font-weight: normal; color: #333333;font-size: 18px;">Basic</span><br/><span>Free</span><br/>
<div class="apply-button-search" style="float: none; margin: auto; margin-bottom: 5px;">
<input class="profilebtn" type="button" style="width:100px !important; margin-top: 1px;" value="Start now" onclick="window.location.href='<?php e(SITE_URL."thanks");?>'">
<?php $sending = SITE_URL."thanks";
$this->Session->setFlash(__("Sorry! You are unauthorized user. Contact us at help@example.com", true), 'default', array('class' => 'notclass'));
echo "<script type='text/javascript'> window.location.href='".$sending."';</script>";
die;?>
我收到此错误
Fatal error: Call to undefined method SessionHelper::setFlash() in /var/www/html/example/app/webroot/testdemo/app/views/fronts/abc.ctp on line 123
所以我只想如何使用这个会话助手逻辑从我的 .ctp 文件中设置闪存消息。
谢谢
【问题讨论】:
-
您应该了解
SessionComponent和SessionHelper之间的区别。Components是Controller的扩展,Helpers是View的扩展。因此,在您查看文件中,您实际上是在调用SessionHelper,而setFlash不是SessionHelper的方法。 -
感谢@FazalRasel 的回复让我看看 SessionHelper 和 SessionComponent 的区别
标签: javascript php jquery session cakephp