【问题标题】:Controller Not loading in CI控制器未在 CI 中加载
【发布时间】:2015-06-03 08:45:34
【问题描述】:

我在应用程序/控制器中有 2 个控制器

  1. Welcome.php
  2. pages.php

我正在通过这个 url 访问welcome.php

http://opunletter.com/index.php/welcome/

但是在访问http://opunletter.com/index.php/pages/

我收到以下错误

404 页面未找到

未找到您请求的页面。

我无法找出错误。请帮忙!

class Pages extends Controller {

    function search($search_terms = '')
    {
        // If the form has been submitted, rewrite the URL so that the search
        // terms can be passed as a parameter to the action. Note that there
        // are some issues with certain characters here.
        if ($this->input->post('q'))
        {
            redirect('/pages/search/' . $this->input->post('q'));
        }

        if ($search_terms)
        {
            // Load the model and perform the search
            $this->load->model('page_model');
            $results = $this->page_model->search($search_terms);
        }

        // Render the view, passing it the necessary data
        $this->load->view('search_results', array(
            'search_terms' => $search_terms,
            'results' => @$results
        ));
    }
}

【问题讨论】:

  • 你能告诉我们你的页面控制器代码吗?

标签: php codeigniter


【解决方案1】:

尝试使用extends CI_Controllerconstruct(),如下所示:

class Pages extends CI_Controller 
{
    function __construct()
    {
        parent::__construct();
    }

    function search($search_terms = '')
    {
        ...
    }
}

并且您应该在 CI3 中使用控制器名称 Pages.php(大写首字母)而不是 pages.php

【讨论】:

  • CodeIgniter v2.x 还是 v3.x?
  • 您应该在 CI3 中使用控制器名称 Pages.php(大写首字母)而不是 pages.php
  • 将文件重命名为 /application/controllers/Pages.php
  • 你错过了方法。您正在尝试访问index.php/pages,这意味着index.php/pages/index。您的控制器没有index 功能,请尝试使用search 方法。 http://opunletter.com/index.php/pages/search,它正在工作
猜你喜欢
  • 2012-04-16
  • 1970-01-01
  • 2012-10-18
  • 2016-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-30
相关资源
最近更新 更多