我一直在CakePHP网站工作,几乎完成,除了标题上的问题,我需要做的是重定向到一个页面,如果用户还没有足够的访问级别可以继续执行,并且如果您在地址栏中写入url,但实际上效果不错,但是当按下应该指向相同地址的按钮时不会。CakePHP与ACL不重定向时没有足够的权限
这是我的AppController类
class AppController extends Controller {
public $components = array(
'Acl',
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers')
)
),
'Session'
);
public $helpers = array('Html', 'Form', 'Session');
public function beforeFilter() {
//Configure AuthComponent
//debug($this->params,true);
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'posts', 'action' => 'add');
$this->Auth->authError = "Error";
if (isset($this->params['requested'])) $this->Auth->allow($this->action);
}
这是一个链接的例子来“添加”页面,如果用户不允许执行此操作时,应重定向到配置的页面在我的AppController
<?php echo $this->Html->link($this->Html->image("add.png", array("alt" => "Agregar nueva encuesta","title" => "Agregar nueva encuesta")),
array('controller'=>'Surveys','action'=>'add',$beneficiary['Beneficiary']['id']),
array('escape' => false));?>
因此,要明确,如果用户写地址,如果“MYSERVER /受益人/添加/参数”被重定向到一个表明他不能这样做,操作的页面,但他按下链接什么也没有发生,他不能添加任何东西,但我需要那个方向。
我将不胜感激任何意见。
我希望我的解释很清楚,我的英语是远远不够完善:)
编辑:
我决定跟随用户奔希区柯克的建议有关使用Web调试“查尔斯”。这是我得到
地址栏
请求 GET /项目/ SUISEPV2 /受益人/编辑/ 1 HTTP/1.1 主机本地主机 的User-Agent的Mozilla/5.0(Windows NT的6.3书面方式; WOW64; rv:26.0)Gecko/20100101 Firefox/26.0 接受text/html,application/xhtml + xml,application/xml; q = 0.9,/; q = 0.8 Accept-Language es-ES,es; q = 0.8,en-US; q = 0.5,en; q = 0.3 Accept-Encoding gzip,deflate Cookie CAKEPHP = 7399cvgls9gurk37ubes1fknf0 连接保持活动
Responde HTTP/1.1 302实测值 日期星期一,2014年1月20日16时54分56秒GMT 服务器的Apache/2.4.7(Win32的)的OpenSSL/0.9.8y PHP/5.4.22 X-Powered By PHP/5.4.22 Location myserver/Projects/SUISEPV2/posts/add Content-Length 0 Keep-Alive timeout = 5,max = 100 连接保持活动 Content-Type text/html;字符集= UTF-8
按下链路
请求: GET /项目/ SUISEPV2 /受益者/编辑/ 1 HTTP/1.1 主机本地主机 用户代理的Mozilla/5.0(Windows NT的6.3; WOW64; rv:26.0)Gecko/20100101 Firefox/26.0 接受text/html,application/xhtml + xml,application/xml; q = 0.9,/; q = 0.8 Accept-Language es-ES,es; q = 0.8,的en-US; q = 0.5,连接; q = 0。3 接受编码的gzip,放气 Referer的MYSERVER /项目/ SUISEPV2 /受益人 曲奇的CakePHP = 7399cvgls9gurk37ubes1fknf0 连接保持活动
响应: HTTP/1.1 302实测值 日期星期一,2014年1月20日16时55分: 33 GMT 服务器Apache/2.4.7(Win32)OpenSSL/0.9.8y PHP/5.4.22 X-Powered-By PHP/5.4.22 Location myserver/Projects/SUISEPV2 /受益人 Content-Length 0 Keep-活动超时= 5,最大= 100 连接保持活动 Content-Type text/html; charset = UTF-8
不幸的是我仍然看不出有什么问题。
不应该链接'控制器'=>'受益人',而不是'控制器'=>'调查'? –
在这种情况下,该按钮的操作是向选定的受益人添加一项调查,但并不重要,即使我尝试编辑或删除用户不允许执行的任何操作,问题也会发生。 – user3013960
您可能会进入重定向循环。我试着运行Charles(Web代理)并检查发送给服务器的内容,以及返回的内容。 –