|
我的配置文件config.php如下:
$config['base_url'] = 'http://localhost:8080';(我加的)
$config['index_page'] = 'index.php';
.
.(中间没有改动动省略。。。。)
.
$config['css'] = "mystyles.css";(我加的)
-----------------------------------------------------
我的routers.php文件如下:
$route['default_controller'] = "Start";
$route['404_override'] = '';
-----------------------------------------------------
我的start.php文件如下:
<?php
class Start extends CI_Controller {
var $base;
var $css;
function Start()
{
parent::CI_Controller();
$this->config->load('config');
$this->base = $this->config->item('base_url','config');
$this->css = $this->config->item('css');
}
function index($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', $data);
}
}
?>
---------------------------------------------------------------------------------
我的testview.php文件如下:
<html>
<head>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'http:\/\/www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns="http:\/\/www.w3.org/1999/xhtml">
<title>Web test Site</title>
<base href="<?php echo "$base"; ?>">
<link rel="stylesheet" type="text/css" href="<?php echo "$base/$css";?>">
</head>
<body>
<h1><?php echo $mytitle; ?> </h1>
<p class="test"> <?php echo $mytext; ?> </p>
</body>
</html>
-----------------------------------------------------
为什么我在运行的时候会如下报错误:
Fatal error: Call to undefined method CI_Controller::CI_Controller() in D:\phpnow\htdocs\CodeIgniter\application\controllers\start.php on line 7
-----------------------------------------
要是我不要 parent::CI_Controller();这句代码,即我的start.php文件如下:
<?php
class Start extends CI_Controller {
var $base;
var $css;
function Start()
{
#parent::CI_Controller();
$this->config->load('config');
$this->base = $this->config->item('base_url','config');
$this->css = $this->config->item('css');
}
function index($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', $data);
}
}
?>
则报如下错误:
A PHP Error was encounteredSeverity: Notice
Message: Undefined property: Start: config
Filename: controllers/start.php
Line Number: 8
Fatal error: Call to a member function load() on a non-object in D:\phpnow\htdocs\CodeIgniter\application\controllers\start.php on line 8
我该怎么加载config.php这个里面的配置啊?比如我想要我自己定义的$config['css'] = "mystyles.css";(我加的)这个变量。我的start.php该怎么写啊?是不是我对codeigniter理解有错误?是语法不对呢?还是我的配置有问题?
(要是直接输出'HELLOWORLD'这样简单的东西却不报错了。。。。)
请高手帮忙啊。小弟在此谢过了!
|
|