check() and comparison is really a bad idea
the first returns bool, how should that ever === to a string?
wrapping that with !empty() makes this completely wrong
if(!empty($this->request->session()->check('Auth.User.role') === 'superadmin')){
Try
if ($this->request->session()->read('Auth.User.role') === 'superadmin') {}
instead
Am Donnerstag, 28. Mai 2015 15:54:47 UTC+2 schrieb Bayezid Alam:
>
> Hi All,
>
> I want to set an authorization in the registration of a form using CakePHP
> 3.0.
>
> Before asking here, i tried below things but no luck in my favor.
>
> Suppose i have role field in the usersTable like 'superuser', 'admin',
> 'user'.
>
> I want to provide permission superuser to make all the things like create
> admin and user. and then admin can create admin and user, and user can make
> user only.
>
> The code i tried in the add function of UsersController.
>
> if($this->Auth->user['role'] === 'superuser'){
> $roles = $this->Users->find('list');
> } elseif ($this->Auth->user['role'] === 'admin') {
> $roles = $this->Users->find('list')->where(['Users.role !==' =>
> 'superuser']);
> } else {
> $roles = $this->Users->find('list')->where(['Users.role' => 'user']);
> }
>
> after failing i tried below things in the add.ctp
>
> if(!empty($this->request->session()->check('Auth.User.role') ===
> 'superadmin')){
> echo $this->Form->input('role',['options' => ['admin' => 'Admin',
> 'user' => 'User']]);
> } elseif(!empty($this->request->session()->check('Auth.User.role')
> === 'admin')){
> echo $this->Form->input('role',['options' => ['user' => 'User',
> 'icr' => 'ICR', 'routing' => 'Routing']]);
> } else {
> echo $this->Form->input('role', ['options' => ['user' =>
> 'User']]);
> }
>
> Could you please suggest on this regard or are there any easiest ways to
> do so?
>
>
> http://stackoverflow.com/questions/30487160/how-to-set-authorization-wise-view-in-the-form-in-cakephp-3-0
>
> Thanks
>
> Bayezid
>
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.