[英]How to check query string is null if variable is not in url using codeigniter?
我想檢查查詢字符串變量是否為空。
提交前我有兩個網址:
http://localhost/Demotest/index.php?m=admin_controller&t=products&s=backend
提交后:
http://localhost/Demotest/index.php?m=admin_controller&t=products&s=backend&pid=2045
我在代碼中檢查了pid:
$pid = $_GET['pid'];
但是這里pid在提交頁面之前是未知的
表單的操作:
<form action="<?=$this->config->base_url();?>index.php?m=admin_controller&t=add_product&s=backend&pid=<?=$item->product_id?>" method="post" name="form" >
對於您正在做的事情,您不是在檢查某些內容是否明確為空,而是檢查它是否已設置。 如果它不在 URL 中,則它是未定義的。 你可以做的是:
$pid = null; // set your variable so you can check it later
if (isset($_GET['pid']))
{
$pid = $_GET['pid']; // set a value if it exists
}
if (!is_null($pid))
{
// stuff to do with $pid if it was set before
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.