我正在为我的网站创建一个搜索我的网站页面的搜索框。为此,我创建一个包含页面名称作为键的数组,它的链接作为值。如下所示
<?php
$linkArray = array(
'Add New Vendor' => base_url().'index.php/vvendor',
'Add New Plan' => base_url().'index.php/plan',
'venodr page' => base_url().'index.php/vendor',
'Employee' => base_url().'index.php/employee'
);
?>
和
之类的搜索框<input type="text" name="search_box" />
如何以codeigniter的方式做到...... ???
答案 0 :(得分:1)
写入您的控制器功能:
$search_box=$_POST['search_box'];
$linkArray = array(
'Add New Vendor' => base_url().'index.php/vvendor',
'Add New Plan' => base_url().'index.php/plan',
'venodr page' => base_url.'index.php/vendor',
'Employee' => base_url.'index.php/employee'
);
if (array_key_exists($search_box, $linkArray )) {
echo "FOUND: ".$search_box;
}
答案 1 :(得分:0)
$searchParam = 'Add New Plan';
$linkArray = array(
'Add New Vendor' => base_url().'index.php/vvendor',
'Add New Plan' => base_url().'index.php/plan',
'venodr page' => base_url.'index.php/vendor',
'Employee' => base_url.'index.php/employee'
);
foreach($linkArray as $key => $value)
{
$pattern = $key;
$subject = $searchParam;
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3);
if($matches)
{
echo $value;
}
}