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.
extend CI_Controller
instead ofextend Controller
Use
__construct
for constructors instead of the class name.function __construct(){ parent::__construct(); // More stuff }
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>
精彩评论