Welcome Guest, Not a member yet? Register   Sign In
CI4: Pass Data From Filter to Controller
#4

(04-10-2021, 09:10 AM)h4n Wrote: In my case, it's a rest api with just jwt token with no username or password. In the filter, the user id will be decoded from the token and need to pass to controller. How to modify $this->request ?

 I used as follows


in the filter
-------------
public function before(RequestInterface $request, $arguments = null){
.....

              $user= new \StdClass();
            $user->user_id =123;  //GOT from JWT
            $user->user_name="Name test"; //GOT from JWT

            $request->user =$user;
            return $request;

in targeted controller
-------------
$user_id = $this->request->user->user_id;
$user_name = $this->request->user->user_nam;
Reply


Messages In This Thread
CI4: Pass Data From Filter to Controller - by h4n - 04-10-2021, 04:39 AM
RE: CI4: Pass Data From Filter to Controller - by Janaka - 10-18-2022, 02:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB