代码点火器在模板模态中传递搜索数据


Codeigniter Passing Search Data in a Template Modal

>我正在尝试为我的网站实现搜索功能。我面临无法通过模板传递数据的错误。即使我尝试使用网站包含的关键字进行搜索,我也会在搜索查询中得到一个空白页。我的默认控制器是页面。

主布局视图 :

<?php $this->load->view('templates/' .$subview); ?>

页面控制器。我认为我无法从_search传递数据。

public function index() {
    // Fetch the page template
    $this->data['page'] = $this->page_m->get_by(array('slug' => (string) $this->uri->segment(1 , 'homepage')), TRUE); 
    count($this->data['page']) OR show_404(current_url());
    // Fetch the page data
    $method = '_' . $this->data['page']->template;
    if (method_exists($this, $method)) {
        $this->$method();
    }
    else {
        log_message('error', 'Could not load template ' . $method .' in file ' . __FILE__ . ' at line ' . __LINE__);
        show_error('Fail : ' . $method);
    }
    // Load the view
    $this->data['subview'] = $this->data['page']->template;
    $this->load->view('_main_layout', $this->data);
}
private function _page(){ // standart page template, just showing for how i do
    $this->load->model('page_m');
    $this->data['pages'] = $this->page_m->get();
}
private function _search(){
    $this->load->model('search_m'); // problem is here i think
}

搜索控制器,关键字功能:

 function keyword()
{
    $keyword = $this->input->post('keyword');
    $this->data['results'] = $this->search_m->search($keyword);
    $this->data['subview'] = 'search';
    $this->load->view('_main_layout',$this->data);
}

搜索型号:

 function search($keyword)
 {
    $this->db->like('body',$keyword);
    return parent::get();
 }

搜索视图:

  <?php if (count($results)): foreach ($results as $result): ?>
    <?php echo $result->title; ?>
    <?php echo $result->body; ?>
  <?php endforeach; endif; ?>

这给出了未定义的变量错误。如果编辑该搜索视图代码,则:

<?php if(isset($results)): ?>
<?php if (count($results)): foreach ($results as $result): ?>
<?php echo $result->title; ?>
<?php echo $result->body; ?>
<?php endforeach; endif; endif; ?>

在此搜索查询之后,我收到一个空白页,这意味着我认为我无法获取结果数据。我在这里错过了什么?

我看到您加载模型,但没有调用函数。我是在看什么吗?

您的搜索控制器看起来不像是从默认控制器继承的,是吗?你正在删除我们需要看到的所有代码