我正在一点一点地自学 PHP OOP...
我无法让它按照我想要的方式工作,我正在尝试这样做:
http://localhost/test/class.php?action=delete
public $action;
public function __construct()
{
$this->action = isset($_GET['action']) ? $_GET['action'] : null;
$this->db = new Db();
$this->Select($action);
}
private function Select($action)
{
if ($action = 'delete')
{
echo "Here";
}
}
}
我认为这是非常基本的..但我自己无法得到解决方案..屏幕只是空白,没有错误,并且不显示任何内容。所以我无法找到解决方案...
谢谢
最佳答案
您可以在类的构造函数中传递 $_GET
:
Class GetClass {
public $action;
public function __construct($get){
$this->action = isset($get['action']) ? $get['action'] : null;
$this->db = new Db();
$this->Select($this->action);
}
private function Select($action){
if (strtolower($action) == 'delete') {
echo "Here";
}
}
}
$getClass = new GetClass($_GET);
关于php - 在类里面使用 $_GET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30708764/