简单的Codeigniter建议

时间:2015-09-10 02:56:49

标签: php codeigniter

版本:CodeIgniter-2.2.4

我非常了解PHP和一些基本的OOP。我是Codeigniter的初学者。我下载Codeigniter并解压缩。我创建了一个文件夹,在我的“htdocs”文件夹中命名为“first_application”。我只编辑了database.php并输入数据库主机为“localhost”,数据库用户为“root”数据库密码为空。

数据库名称=“first_application”。

然后,我创建了一个名为Hello_world.php的控制器类。这是代码..

<?php
defined('BASEPATH') OR exit ('No direct script access allowed);
class Hello_world extends CI_Controller {
    function index()
    {   
        $data['title']='My first application';
        $data['message']='My name is samol';
        $this->load->view('helloworld', $data);
    }
}
?>

然后在“views”文件夹上创建一个文件。这是代码..

<html>
<head>
<title><?php echt $title;?></title>
</head>
<body>
</body>
<h1><?php echo $message?></h1>
</body>
</html>

现在,我输入了我的浏览器http://localhost/first_application/index.php/Hello_world。我已经看到了这个错误信息。

Parse error: syntax error, unexpected 'title' (T_STRING) in C:\xampp\htdocs\first_application\application\controllers\Hello_world.php on line 6

我探索了许多教程网站并阅读了许多PDF书籍,但我没有成功。给我一些建议来覆盖这个问题。

2 个答案:

答案 0 :(得分:1)

<div class="post">
    <span><a>Posted By Adam</a></span>
    <img width="100%" src="uimg/adam-levine-600.jpg">
</div>

应该是:

<title><?php echt $title;?></title>

答案 1 :(得分:1)

您缺少单引号

defined('BASEPATH') OR exit ('No direct script access allowed);

应该是

defined('BASEPATH') OR exit ('No direct script access allowed');

(在允许的单词之后,用单引号结束字符串),不确定你是否将它放入stackoverflow是错误的,或者如果那是你的实际脚本代码,因为这仍然是语法错误,唯一的方法是,该代码是否与错误在同一行。

然而,这不是有问题的语法错误,@ nicolas描述了正确的错误,但只是要注意此页面上还有其他错误。