SpeedPHP框架学习-.基础及MVC理解_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了SpeedPHP框架学习-.基础及MVC理解_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2069字,纯文字阅读大概需要3分钟。
内容图文
Controller为控制器文件。程序从index.php开始执行[php]
<?php
define("SP_PATH",dirname(__FILE__)."/SpeedPHP");
define("APP_PATH",dirname(__FILE__));
$spConfig = array(
"db" =>array(
'host' =>'localhost',
'login' =>'root',
'password' =>'root',
'database' =>'test',
),
'view' => array(
'enabled' =>TRUE,
'config'=>array(
'template_dir'=> APP_PATH.'/tpl',
'compile_dir'=> APP_PATH.'/tmp',
'cache_dir'=> APP_PATH.'/tmp',
'left_delimiter'=> '<{',
'right_delimiter'=> '}>',
),
)
);
require(SP_PATH."/SpeedPHP.php");
spRun();
上述程序定义了App和SP的路径,加载了数据库和视图层的配置,加载SP的核心库文件,最后运行整个系统。以上程序运行起来时,会首先到Controller目录下执行main类下的index方法。main类的程序如下:
[php]
<?php
class main extends spController
{
function index(){
$tpl = $this->spArgs("tpl","green");
$guestbook =spClass("guestbook");
$this->results= $guestbook->findAll();
$this->display("{$tpl}/index.html");
}
function write(){
$guestbook =spClass("guestbook");
$newrow =array(
'name'=> $this->spArgs('name'),
'title'=> $this->spArgs('title'),
'contents'=> $this->spArgs('contents'),
);
$guestbook->create($newrow);
echo "return";
}
}
从index.php过来默认调用main方法的index函数,在本例中这个函数首先设定模板名参数(tpl)。再新建一个model。使用model的findall方法,查找全部数据库信息。最后使用tpl模板显示结果。上述控制器程序,必须继承自spController类,方法名就是调用的action名。在程序中显式调用时路径为index.php?c=main&a=write。Model如下所示,是和数据库表同名的类文件。这个model必须继承自spModel,同时设置了主键和表名属性。
[php]
<?php
class guestbook extends spModel
{
var $pk = "id"; //每个留言唯一的标志,可以称为主键
var $table ="guestbook"; // 数据表的名称
}
在tpl模板目录里的index.html文件下使用如下所示程序,格式化输出结果。
[html]
<{foreach from=$results item=one}>
<{$one.title}>
<{$one.name}>:
<{$one.contents}>
<{/foreach}>
http://www.bkjia.com/PHPjc/477933.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/477933.htmlTechArticleController为控制器文件。程序从index.php开始执行 [php] ?php define(SP_PATH,dirname(__FILE__)./SpeedPHP); define(APP_PATH,dirname(__FILE__)); $spConfig = array( db =arr...
内容总结
以上是互联网集市为您收集整理的SpeedPHP框架学习-.基础及MVC理解_PHP教程全部内容,希望文章能够帮你解决SpeedPHP框架学习-.基础及MVC理解_PHP教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。