2016-02-29 6 views
1

我想檢查查詢字符串變量是否爲null。如果使用codegniter變量不在url中,如何檢查查詢字符串爲空?

我有兩個網址之前提交:

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" > 
+0

你怎麼通過'pid'? – urfusion

+0

我在表單提交時傳遞了pid –

+0

你怎麼生成'pid'? – urfusion

回答

0

因爲你在做什麼,你不檢查,看看是否有是專門爲空,而如果它的設置。如果它不在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 
} 
相關問題