php - codeigniter form not working -
i trying create search form in codeigniter site header, everytime form submitted, receive 404 error saying page cannot found! have attempted create link test page , gave me same error.
please observe code below.
view(site_header)
<?php echo doctype(); ?> <html lang="en"> <link href="<?php echo base_url(); ?>styles/style.css" type="text/css" rel="stylesheet"/> <head> <title>/title> <div id="container"> <div id="search"> <?php echo form_open('search_keyword'); echo form_label("stumble search ", "searchfor"); echo form_input("search","search"); echo form_submit("getsearch","search"); echo form_close(); ?> </div> </div> </head> </html>
model (model_search)
<?php class model_search extends ci_model { public function get_results($search_term){ $query = $this->db->query('select embed, title videos tags '%$search_term%' order rand() limit 1'); return $query->result(); } } ?>
controller (site.php) default controller
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class site extends ci_controller { public function index(){ $this->home(); } public function home(){ $this->load->model("model_get"); $data["results"] = $this->model_get->getrand(); $this->load->view("site_header"); $this->load->view("site_content", $data); $this->load->view("site_footer"); } public function search_keyword() { $this->load->model('model_search'); $search_term = $this->input->post('search'); $data['results'] = $this->model_search->get_results($search_term); $this->load->view('site_header'); $this->load->view('search_content',$data); $this->load->view('site_footer'); } } ?>
results page (search_content)
<body> <link href="<?php echo base_url(); ?>styles/style.css" type="text/css" rel="stylesheet"/> <div id="container"> <div id="intro"> <?php echo heading("search results",1);?> </div> <div id ="content"> <p>stumble videos related <?php echo $search_term; ?> </p> <?php foreach ($results $row) { $title = $row->title; $vid = $row->embed; } echo heading($title, 3); echo $vid; ?> </div> </div> </body>
perhaps missing obvious, think may .htaccess file posted below
(.htaccess)
<ifmodule mod_rewrite.c> rewriteengine on rewritebase /code/ rewritecond %{request_uri} ^system.* rewriterule ^(.*)$ /index.php?/$1 [l] rewritecond %{request_uri} ^application.* rewriterule ^(.*)$ /index.php?/$1 [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.*)$ index.php?/$1 [l] </ifmodule>
codeigniter urls need both controller name , method.
form_open('site/search_keyword')
Comments
Post a Comment