您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 鹰潭分类信息网,免费分类信息发布

php利用zendframework编程实例

2024/6/1 13:30:25发布46次查看
本文章参考《php顶级框架zendframe开发实战》第四章内容,并完整实现...
首先将用到的css文件下载下来:http://download.csdn.net/download/unityoxb/4058802
解压后把default和common两个文件复制到public/skins目录下;
1、用到的数据库文件mysql.sql
create table if not exists `core_pages`( `id` int(10) unsigned not null auto_increment comment '页面唯一id', `cid` int(10) unsigned not null default '0' comment '分类id', `uid` int(10) unsigned not null default '0' comment '用户id', `title` varchar(255) not null comment '页面标题', `body` text not null comment '内容', `status` tinyint(4) not null default '1' comment '是否发布', `createtime` int(11) not null default '0' comment '创建页面时间', `updatetime` int(11) not null default '0' comment '修改页面时间', `comment` tinyint(4) not null default '0' comment '页面是否评论功能', `start` tinyint(4) not null default '0' comment '页面级别', `top` tinyint(4) not null default '0' comment '置顶', primary key (`id`))engine=innodb default charset=utf8;
打开mysql,使用source mysql.sql即可创建表结构2、配置application.ini文件(hahacom/applicaton/configs)
主要配置zend framework连接mysql
[development : production]phpsettings.display_startup_errors = 1phpsettings.display_errors = 1resources.frontcontroller.params.displayexceptions = 1resources.db.adapter = pdo_mysqlresources.db.params.host = localhostresources.db.params.username = rootresources.db.params.password = rootresources.db.params.dbname = test --这是数据名称resources.db.isdefaulttableadapter = trueresources.db.params.driver_options.1002 = set names utf8;
3、public/index.php
// define application environmentdefined('application_env') || define('application_env', (getenv('application_env') ? getenv('application_env') : 'development')); //修改成测试环境
4、创建文章展示model(model主要存储数据模型类似javabean,或者从数据库获取数据并保存在内存里)执行命令:zf create model page 
会自动生成一个models/page.php文件
getadapter(); $select = $db->select(); /*if($where != null) { //$select->where(' star = ? ', $where); //$sql = $db->quoteinto(select * from `core_pages` where `star`= ?, $where); //$result = $db->query($sql); $select->from('core_pages','*')->where('star = ?', $where)->limit(1); }*/ $select->from('core_pages','*'); if(count($where)>0) { foreach($where as $key=>$value) $select->where($key.' = ?',$value); } //$row = $result->fetch(); $row = $db->fetchall($select); if($row) { return $row; } else { echo =================; return null; } } public function getpages($where = null) { $db = zend_db_table::getdefaultadapter(); if(is_numeric($where)) { //$row = $db->find($where)->current(); $select = $db->select(); $select->from('core_pages','*'); $select->where('id = ?', $where); $row = $db->fetchrow($select); } if(is_array($where) && count($where)>0) { $select = $db->select(); $select->from('core_pages','*'); foreach($where as $key=>$value){ $select->where($key.'=?', $value); } $row = $db->fetchall($select); } if($row) { return $row; } else { echo =================; return null; } }}?>
5、创建controller执行命令: zf create controller news   会自动生成controllers/newscontroller.php
1, 'comment'=>1); $newsstar = $modelpage->getpage($where); //print_r($newsstar); $this->view->news = $newsstar; //$this->view->name = hahaha; }}
执行命令: zf create controller page 和 zf create action detail page会自动生成 controllers/pagecontroller.php
_request->getparam('id'); $modelpage = new application_model_page($id); //if($modelpage == null) //print_r('=============================='); //print_r($id); //print_r($modelpage); $page = $modelpage->getpages($id); $this->view->page = $page; }}
5、接下来创建视图文件/views/scripts/news/index.phtml
news[0]['title'].;echo $this->news[0]['body'];//echo $this->name;if($this->news){ /*echo
; // print_r($this->news); foreach($this->news as $val) { echo ..$val['title']..; } echo ; */ echo ; echo $this->partialloop('row_pages.phtml', $this->news); echo ;}?>
/views/scripts/row_pages.phtml

>title; ?> 发表时间: createtime); ?>
/views/scripts/page/detail.phtml
page['title'].; echo 发表:.date('y-m-d', $this->page['createtime']).; echo ; echo $this->page['body'];?>
运行截图:
点击链接:
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了php利用zendframework编程实例,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
鹰潭分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录