Accessing $this->request in view without having to pass it into view - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: Accessing $this->request in view without having to pass it into view (/showthread.php?tid=76955) |
Accessing $this->request in view without having to pass it into view - Diaan - 07-07-2020 Is there a way of accessing the incomingRequest class within a view without having to pass it in a data array. I would like to do the same with the db class so I can call $this->db->query() directly in the view. for instance I did the following initially: Code: public function location() But is there no nice way of accessing $this->request directly in the view without having to pass it into view I want to do something like this: Code: <?php without having to pass the request directly to the $data array. What I have done as a work around is the following: Code: <?php Code: <?php Code: <?php This provides access to the request and db but I would need to create a method in helper functions class for each type of method I would want to call against the request class. Many thanks in advance for suggestions, and or a better way of doing this. RE: Accessing $this->request in view without having to pass it into view - InsiteFX - 07-08-2020 PHP Code: $db = db_connect(); RE: Accessing $this->request in view without having to pass it into view - mhsagor - 08-17-2021 You can create an instance of request service in view like that, Code: $request = \Config\Services::request(); |