0

I am working on creating a search box for my website which search my website pages. for this i create an array of containing a page name as key and it's link as a value. like below

   <?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'
    );
    ?>

and a search box like

<input type="text" name="search_box" />

how to do it in the codeigniter way...???

always-a-learner
  • 3,671
  • 10
  • 41
  • 81

2 Answers2

1

Write in your controller function:

$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;
    }

--Reference--

VBMali
  • 1,360
  • 3
  • 19
  • 46
  • 1
    For smarter search, you can do for example `$linkArray = array('add new vendor'...); if (array_key_exists(mb_strtolower($search_box), $linkArray))`. – Gras Double Aug 10 '15 at 11:08
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;
    }
}
Kruti Aparnathi
  • 175
  • 1
  • 11