Welcome Guest, Not a member yet? Register   Sign In
[Controller Filters] Controller Index problem
#1

Hello,

I created filters for some of my webpage, the pattern is like this


PHP Code:
public $filters = [
'isLoggedIn' => ['before' => ['user/*','home/*','edisi/*','rubrik/*','article/*']],
'isAdmin' => ['before' => ['user/*','edisi/*','rubrik/*']],
]; 

But the problem is when I visit index method of those controllers, the filter won't applied because we usually visit https://example.com/user instead of https://example.com/user/index.

So my temporarily solution is something like this

PHP Code:
public $filters = [
 
'isLoggedIn' => ['before' => ['user','user/*','home','home/*','edisi','edisi/*','rubrik','rubrik/*','article','article/*']],
'isAdmin' => ['before' => ['user','user/*','edisi','edisi/*','rubrik','rubrik/*']],
]; 

Am I missing something here? Is there any other elegant solution?
Reply
#2

The controller index method is the default method that is called when no controller
method is specified.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Depending on how your routes are setup, you can often use the wildcard without the slash to make it work:

PHP Code:
public $filters = [
  
'isLoggedIn' => ['before' => ['user*','home*','edisi*','rubrik*','article*']],
  
'isAdmin' => ['before' => ['user*','edisi*','rubrik*']],
]; 
Reply
#4
Thumbs Up 

(06-19-2020, 10:37 AM)kilishan Wrote: Depending on how your routes are setup, you can often use the wildcard without the slash to make it work:

PHP Code:
public $filters = [
  'isLoggedIn' => ['before' => ['user*','home*','edisi*','rubrik*','article*']],
  'isAdmin' => ['before' => ['user*','edisi*','rubrik*']],
]; 


Why I did not think of this. Thanks for your reply Kilishan
Reply




Theme © iAndrew 2016 - Forum software by © MyBB