xhceml 发表于 2012-3-1 11:53:27

请教

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Index extends CI_Controller {

        function __construct()
                {
                parent::__construct();
        }
        /**
       * Index Page for this controller.
       *
       * Maps to the following URL
       *                 http://example.com/index.php/welcome
       *        - or -
       *                 http://example.com/index.php/welcome/index
       *        - or -
       * Since this controller is set as the default controller in
       * config/routes.php, it's displayed at http://example.com/
       *
       * So any other public methods not prefixed with an underscore will
       * map to /index.php/welcome/<method_name>
       * @see http://codeigniter.com/user_guide/general/urls.html
       */
public function index()       
{
       
                $data['aaq']="另一个";
                $data['title'] = "My Real Title";
                $data['heading'] = "My Real Heading";
      $data['welcome']="欢迎使用ci框架";
                $this->load->view('welcome_message', $data);
       
        }
public function blog()
        {
                echo '这是测试';
        }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

用http://127.0.0.1/ci/index.php 可以访问 正常
用http://127.0.0.1/ci/index.php/blog 出错404 Page Not Found The page you requested was not found.

请高人帮我解决下谢谢

lynn.wang 发表于 2012-3-1 14:28:28

http://127.0.0.1/ci/index.php
是不是跳转到了默认的 welcome 的页面呢?

http://127.0.0.1/ci/index.php/blog
是指去application/controller/ 下找 blog.php 这个文件
你检查一下看

留痕 发表于 2012-3-1 16:26:27

http://127.0.0.1/ci/index.php/index/blog

suxiaolu 发表于 2012-3-1 19:52:41

类名最好和文件名保持一致

lynn.wang 发表于 2012-3-1 20:01:54

你去自习看看 CI 的 url2楼讲的是对的
只是你这个命名等尽量按照规范
而且一般少用 Index做类名的
你这个就可以直接改成用 Blog 做类名
blog方法的echo 放到index 最后面就可以了
页: [1]
查看完整版本: 请教