Skip to content

Instantly share code, notes, and snippets.

@fahmiegerton
Created March 30, 2021 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fahmiegerton/c490d0410ee4e03d13c0b2ecc7a9cf94 to your computer and use it in GitHub Desktop.
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.
<?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