controller为控制器文件。程序从index.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]
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 "
}
}
从index.php过来默认调用main方法的index函数,在本例中这个函数首先设定模板名参数(tpl)。再新建一个model。使用model的findall方法,查找全部数据库信息。最后使用tpl模板显示结果。上述控制器程序,必须继承自spController类,方法名就是调用的action名。在程序中显式调用时路径为index.php?c=main&a=write。Model如下所示,是和数据库表同名的类文件。这个model必须继承自spModel,同时设置了主键和表名属性。
[php]
class guestbook extends spModel
{
var $pk = "id"; //每个留言唯一的标志,可以称为主键
var $table ="guestbook"; // 数据表的名称
}
在tpl模板目录里的index.html文件下使用如下所示程序,格式化输出结果。
[html]
:
ShopNC多用户商城,全新的框架体系,呈现给您不同于以往的操作模式,更简约的界面,更流畅的搜索机制,更具人性化的管理后台操作,更适应现在网络的运营模式解决方案,为您的创业之路打下了坚实的基础,你们的需求就是我们的动力。我们在原有的C-C模式的基础上更增添了时下最流行的团购频道,进一步的为您提高用户的活跃度以及黏性提供帮助。ShopNC商城系统V2.4版本新增功能及修改功能如下:微商城频道A、商城
0
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号