10520

can someone please put this in english for me PHP Cakephp

Question:

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); }

Answer1:

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

<ul><li>

<a href="http://php.net/manual/en/function.in-array.php" rel="nofollow">in_array</a>

</li> <li>

<a href="http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary" rel="nofollow">ternary Operator</a>

</li> </ul>

Happy To Help :)

Answer2:

public function isAuthorized() {

<strong>//fetches the current user's role (admin,user,editor,visitor,etc..)</strong><br /> $role = $this->Auth->user('role');<br /><strong>//assigns a null value</strong><br /> $neededRole = null;<br /><strong>//fetches the param for prefix and assigns to $prefix,if not found,assigns null</strong><br /> $prefix = !empty($this->params['prefix']) ? $this->params['prefix'] : null;<br /><strong>//if $prefix not null & if $prefix has route configured assign $prefix to $neededRole</strong><br /> if (!empty($prefix) && in_array($prefix, Configure::read('Routing.prefixes'))) { $neededRole = $prefix;<br /> } return (empty($neededRole) || strcasecmp($role, 'admin') == 0 || strcasecmp($role, $neededRole) == 0); }<br /><strong>//the rest i'm not too sure..</strong>

Recommend

  • cakephp automatic logout from application when creating a user with existing email address
  • WebApi Custom System.Web.Http.AuthorizeAttribute does not recognize custom ClaimsPrincipal
  • Custom authorization based on url in ASP.NET MVC
  • POST array to Spring's controller via AJAX
  • Django: DRY principle and UserPassesTestMixin
  • SIP Makefile fail (gnuwin and mingw)
  • How to generate an asynchronous reset verilog always blocks with chisel
  • Yii2 Login with database
  • Action Pack components in Rails
  • SIP API media codecs
  • Django return user model id with L
  • Configure Spring's MappingJacksonHttpMessageConverter
  • How do I retrieve the user information of a user authenticated with Apache's mod_ldap?
  • Laravel: Getting Session ID oddly truncates when using foreach
  • How do I configure context broker accept post requests from my remote sensor?
  • Button click event not firing in jQuery
  • swift auto completion not working in Xcode6-Beta
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Linker errors when using intrinsic function via function pointer
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • JTable with a ScrollPane misbehaving
  • LevelDB C iterator
  • Authorize attributes not working in MVC 4
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Busy indicator not showing up in wpf window [duplicate]
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • Reading document lines to the user (python)
  • Binding checkboxes to object values in AngularJs
  • Observable and ngFor in Angular 2
  • How can i traverse a binary tree from right to left in java?
  • How to Embed XSL into XML
  • failed to connect to specific WiFi in android programmatically
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF
  • How can I use threading to 'tick' a timer to be accessed by other threads?
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?