skymvc采用单一入口模式,但不是唯一入口,推荐使用两个入口。一个是前台入口,一个是后台入口。 1.前台入口文件实例:index.php 文件名可以自定义 推荐 index 或者 default tpl->rewrite=false; $control->tpl->rewrite_rule=array(array("/index.php/i"),array("index.html")); //配置伪静态结束 $method=isset($_GET['a']) && method_exists($control,'on'.$_GET['a'])? 'on'.$_GET['a']:"onDefault"; $control->$method(); ? 2.后台入口文件:admin.php 文件名可自定义 tpl->tplid="admin"; $control->tpl->currdir="admin"; $control->tpl->rewrite_on=true; $control->tpl->rewrite_rule=array(array("/index.php/","index.html")); $method=isset($_GET['a']) && method_exists($control,'on'.$_GET['a'])? 'on'.$_GET['a']:"onDefault"; $control->$method() ?> 说明:前后台入口文件的差别不大,主要在于 模型 和 控制文件 所在文件夹。 3.控制器文件 indexControl(); } function indexControl() { parent::__construct();//父类初始化 $this->loadModel("index"); //后台 //$this->loadAdminModel("index"); } function onDefault() { $this->tpl->assign("welcome","欢迎使用skymvc,让我们共同努力!"); $this->tpl->assign("who",$_ENV['indexModel']->test()); //后台 //$this->tpl->assign("who",$_ENV['admin_indexModel']->test()); $this->tpl->display("index"); } ?>
4.模型文件 模型文件主要用于处理数据,当然也可以处理其他的逻辑,但不推荐。文件命名规范:类.model.php 如:index.model.php. 模型文件位于模型目录下面:如model目录 例:index.model.php indexModel($base); } function indexModel(&$base) { $this->base=$base; $this->db=$base->db; } function test() { echo "这是模型测试"; } } ?> 模型文件:前后台一样 就存储的地方不一样 5.hello world kymvc框架的hello word ! 如果是自动创建目录的话。 配置好数据库 index.php 入口文件写好。 index.php内容 $method();?> 在ctrl目录下 创建 hello.ctrl.php 文件 helloControl(); } function helloControl() { parent::__construct(); $this->loadModel("hello");//载入模型 可以载入任何模型 但不能是相同类的模型 } //默认执行的动作 命名规范 _disibledevent=>tpl->assign("test",$_ENV['helloModel']->gettest()); $this->tpl->display("hello.html"); } }?> 在model目录下 创建hello.model.php helloModel($base); } function helloModel(&$base) { $this->base=$base; $this->db=$base->$db; } //上面都是不用改的 function gettest(){ return $this->db->getRow("select * from test limit 1");//读取数据 } } ?> 在tpl目录下 新建 hello.html
最新评�