我在Codeigniter的静态页面教程中哪里出了问题?

时间:2013-06-07 19:47:11

标签: php codeigniter

我正在学习https://www.codeigniter.com/user_guide/tutorial/static_pages.html关于学习系统的教程。当它说查看页面时,我收到HTTP 500错误。

正确安装了Codeignitor,并启动了默认的欢迎页面。我只是无法弄清楚我在哪里出错了。

class Pages extends CI_Controller {

public function view($page = 'home')
{

    if ( ! file_exists( APPATH . 'views/pages/' . $page . '.php'))
    {
        // Whoops, we don't have a page for that!
        show_404();
    }

    $data['title'] = ucfirst($page); // Capitalize the first letter

    $this->load->view('templates/header', $data);
    $this->load->view('pages/'.$page, $data);
    $this->load->view('templates/footer', $data);

}

2 个答案:

答案 0 :(得分:0)

APPPATH代替APPATH

答案 1 :(得分:0)

就像已经回答的那样,它是APPPATH

APPPATH是一个包含字符串的常量,如果从控制器调用该字符串,则返回“application /”

试试这个:

public function view($page = 'home')
{

    if ( ! file_exists( APPPATH . "views/pages/{$page}.php"))
    {
        // Whoops, we don't have a page for that!
        show_404();

    } else {

    $data['title'] = ucfirst($page); // Capitalize the first letter

    $this->load->view('templates/header', $data);
    $this->load->view("pages/{$page}", $data);
    $this->load->view('templates/footer', $data);

    }
}