Created
March 30, 2021 18:28
-
-
Save fahmiegerton/c490d0410ee4e03d13c0b2ecc7a9cf94 to your computer and use it in GitHub Desktop.
CodeIgniter 4 to access request class for custom library. Maybe there's another nice way, but this is the only way I could think of.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Library\CustomLibrary; | |
use CodeIgniter\HTTP\RequestInterface; | |
class Request | |
{ | |
/** | |
* Instance of the main Request object. | |
* | |
* @var HTTP\IncomingRequest | |
*/ | |
protected $request; | |
public function __construct(RequestInterface $request) | |
{ | |
$this->request = $request; | |
} | |
public function Request() | |
{ | |
return $this->request; | |
} | |
} | |
class AnotherClass | |
{ | |
public function AnotherFunction() | |
{ | |
$request = (new Request)->Request(); | |
$request->getVar('something'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment