有人可以把这个在英语为我PHP Cakephp [英] can someone please put this in english for me PHP Cakephp
本文介绍了有人可以把这个在英语为我PHP Cakephp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对不起,这是一个蠢的屁股。我在下面的教程中添加管理路由到我的cakephp应用程序,我试图创建一个学习练习。
教程没有很好地解释我想我只是太多的初学者在现实中),我不明白以下,任何人都可以告诉我在这里发生了什么。
public function isAuthorized(){
$ role = $ this-> Auth-> user('role');
$ neededRole = null;
$ prefix =!empty($ this-> params ['prefix'])? $ this-> params ['prefix']:null;
if(!empty($ prefix)&& in_array($ prefix,Configure :: read('Routing.prefixes'))){
$ neededRole =
}
return(empty($ neededRole)|| strcasecmp($ role,'admin')== 0 || strcasecmp($ role,$ neededRole)== 0);
}
解决方案
//此方法提供关于当前认证的用户的角色的信息。
$ role = $ this-> Auth-> user('role');
//首先使用var_dump($ this-> params ['prefix'])检查并查看结果
/ *
*三元运算符,其说$ this-> params ['prefix']不为空
*然后设置$ prefix = $ this-> params ['prefix']否则设置$ prefix = null
* /
$ prefix =!empty($ this-> params ['prefix'])? $ this-> params ['prefix']:null;
/ *
*现在检查数组
* echo< pre>;
* print_r(Configure :: read('Routing.prefixes'));
* echo< / pre>;
*现在下面说如果`$ prefix`不为空,那么在这个数组中搜索`$ prefix`
*值`Configure :: read('Routing.prefixes')`如果
*存在于数组中,然后设置`$ neededRole = $ prefix;
* /
if(!empty($ prefix)&& in_array($ prefix,Configure :: read('Routing.prefixes'))){
$ needRole = $ prefix;
}
/ *下面说说如果$ role == admin然后返回$ role或return $ neededRole * /
return(empty($ neededRole)|| strcasecmp($ role, 'admin')== 0 || strcasecmp($ role,$ neededRole)
参考
帮助:)
I'm sorry for being such a dumb ass. I'm following a tutorial to add admin routing to my cakephp application that I'm trying to create as a learning exercise.
The tutorial isn't hugely well explained (I think I'm just too much of a beginner in reality) and I don't understand the following, could anyone please tell me in english what is happening here.
public function isAuthorized() {
$role = $this->Auth->user('role');
$neededRole = null;
$prefix = !empty($this->params['prefix']) ? $this->params['prefix'] : null;
if (!empty($prefix) && in_array($prefix, Configure::read('Routing.prefixes'))) {
$neededRole = $prefix;
}
return (empty($neededRole) || strcasecmp($role, 'admin') == 0 || strcasecmp($role, $neededRole) == 0);
}
解决方案
where u have probelm???
u can debug one by one
// This method provides information of role about the currently authenticated user.
$role = $this->Auth->user('role');
// you first check with var_dump($this->params['prefix']) and see the result
/*
* this line use ternary operator, its say $this->params['prefix'] is not empty
* then set $prefix = $this->params['prefix'] otherwise set $prefix=null
*/
$prefix = !empty($this->params['prefix']) ? $this->params['prefix'] : null;
/*
*Now check the array
*echo "<pre>";
* print_r(Configure::read('Routing.prefixes'));
* echo "</pre>";
* now below line said if `$prefix` is not empty then search that `$prefix`
* value in this array `Configure::read('Routing.prefixes')` and if it
* exist in the array then set `$neededRole = $prefix;
*/
if (!empty($prefix) && in_array($prefix, Configure::read('Routing.prefixes'))) {
$neededRole = $prefix;
}
/* below line say say that if $role == admin then return $role or return $neededRole */
return (empty($neededRole) || strcasecmp($role, 'admin') == 0 || strcasecmp($role, $neededRole)
Reference
Happy To Help :)
这篇关于有人可以把这个在英语为我PHP Cakephp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文