开发者

codeigniter 2.02 - passing argument - page not found

i use ubuntu 10.10 and codeigniter 2.0.2

i have successfully installed CI by opening welcome index page

later on i was following tutorial and have added new controller to my project:

class Start extends CI_Controller{
    var $base;
    var $css;

    function __construct() {
        parent::__construct();
        $this->base=$this->config->item('base_url');
        $this->css=$this->config->item('css');
        }


    function hello($name){
        $data['css'] = $this->css;
        $data['base'] = $this->base;
        $data['mytitle'] = 'Welcome to this site';
        $data['mytext'] = "Hello, $name, now we're getting dynamic!";
        $this->load->view('testview', $da开发者_开发问答ta);
    }
}

as well as view(testview.php) and css variable in question. then upon trying to test it by executing http://localhost/ci/index.php/index/start/hello/fred i get 404 page not found.

thank you


use this class declaration instead

class Start extends CI_Controller{

and instead of your php4 constructor

use this instead of Start()

function __construct(){
    parent::__construct();
    $this->base=$this->config->item('base_url');
    $this->css=$this->config->item('css');
}

The actual reason you're getting a 404 is because you're telling it to find a function called fred. The url you're probably meaning to hit is this...

http://localhost/ci/index.php/start/hello/fred

Since 2.0.x , Codeigniter has changed their base controller class names and moved everything to php5 style constructors, among other things.

You are probably following a older tutorial.


It seems you have used an old tutorial. In CodeIgniter 2, some things are different.

  1. extend CI_Controller instead of extend Controller
  2. Use __construct for constructors instead of the class name.

    function __construct(){
        parent::__construct();
        // More stuff
    }
    
  3. The url should be http://localhost/ci/index.php/start/hello/fred. CodeIgniter's URLs are used like so:

    http://localhost/ci/index.php/<controller>/<method>/<params>
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜