کدهای کلاس Request
namespace App\\Core;
class Request{
private $params;
private $method;
private $agent;
private $ip;
public function __construct()
{
$this->params = $_REQUEST;
$this->method = $_SERVER['REQUEST_METHOD'];
$this->agent = $_SERVER['HTTP_USER_AGENT'];
$this->ip = $_SERVER['REMOTE_ADDR'];
}
public function method()
{
return $this->method;
}
public function agent()
{
return $this->agent;
}
public function ip()
{
return $this->ip;
}
public function input($key)
{
return $this->params[$key] ?? null;
}
public function isset($key)
{
return isset($this->params[$key]);
}
public function redirect($route)
{
header("location:" . site_url($route));
die();
}
public function __get($name)
{
return $this->params[$name] ?? null;
}
}
کدهای فایل index
use App\\Utilities\\Asset;
use App\\Core\\Request;
include "bootstrap/init.php";
$request = new Request();
echo $request->name;
اینجا نام متد جادویی که استفاده کردیم باید با پارمتر که وارد شده یکسان باشه یعنی مثلا اگر پارامتر test = hello باشه باید نام متدی که استفاده میکنیم هم test باشه