<?php
class DemoController
{
function index()
{
echo('hello world');
}
}
/* End of file democontroller.php */
这个文件里面我们只是建立了一个名为DemoController的对象并包含一个index的方法,该方法输出hello world。下面在index.php中执行DemoController中index方法。
index.php的代码如下
<?php
require('controller/democontroller.php');
$controller=new DemoController();
$controller->index();
/* End of file index.php */
运行index.php,ok如愿我们看到了我们久违的hello world。这两个文件非常简单,但也揭示了一点点mvc的本质,通过唯一入口运行我们要运行的控制器。当然controller部分应该是由uri来决定的,那么我们来改写一下index.php使他能通过uri来决定运行那个controller。
index.php改写代码如下:
<?php
class DemoController
{
function index()
{
$data['title']='First Title';
$data['list']=array('A','B','C','D');
require('view/index.php');
}
}
/* End of file democontroller.php */
view文件夹下index.php文件代码如下: