本文章参考《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 = 1 phpSettings.display_errors = 1 resources.frontController.params.displayExceptions = 1 resources.db.adapter = "PDO_MYSQL" resources.db.params.host = "localhost" resources.db.params.username = "root" resources.db.params.password = "root" resources.db.params.dbname = "test" --这是数据名称 resources.db.isDefaultTableAdapter = "TRUE" resources.db.params.driver_options.1002 = "SET NAMES UTF8;"
3、public/index.php
// Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : '<strong>development</strong>')); //修改成测试环境
4、创建文章展示model(model主要存储数据模型类似javabean,或者从数据库获取数据并保存在内存里)
执行命令:zf create model page
会自动生成一个models/Page.php文件
<?php class Application_Model_Page { protected $_name = 'core_pages'; public $result; public function getPage($where = array()) { $db = Zend_Db_Table::getDefaultAdapter(); // $db = $this->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
<?php class NewsController extends Zend_Controller_Action { public function init() { /* Initialize action controller here */ } public function indexAction() { // action body $modelPage = new Application_Model_Page(); //$star = 1; $where = array('top'=>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
<?php class PageController extends Zend_Controller_Action { public function init() { /* Initialize action controller here */ } public function indexAction() { // action body } public function detailAction() { // action body $id = $this->_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
<?php echo "<h3>".$this->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 $this->partialLoop('row_pages.phtml', $this->News);
echo "
/views/scripts/row_pages.phtml
/views/scripts/page/detail.phtml
<?php echo "<h2>".$this->page['title'].""; echo "发表:".date('Y-m-d', $this->page['createtime']).""; echo "<hr>"; echo $this->page['body']; ?>
运行截图:
点击链接:
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了php利用zendframework编程实例,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

许多用户在选择智能手表的时候都会选择的华为的品牌,其中华为GT3pro和GT4都是非常热门的选择,不少用户都很好奇华为GT3pro和GT4有什么区别,下面就就给大家介绍一下二者。华为GT3pro和GT4有什么区别一、外观GT4:46mm和41mm,材质是玻璃表镜+不锈钢机身+高分纤维后壳。GT3pro:46.6mm和42.9mm,材质是蓝宝石玻璃表镜+钛金属机身/陶瓷机身+陶瓷后壳二、健康GT4:采用最新的华为Truseen5.5+算法,结果会更加的精准。GT3pro:多了ECG心电图和血管及安

为什么截图工具在Windows11上不起作用了解问题的根本原因有助于找到正确的解决方案。以下是截图工具可能无法正常工作的主要原因:对焦助手已打开:这可以防止截图工具打开。应用程序损坏:如果截图工具在启动时崩溃,则可能已损坏。过时的图形驱动程序:不兼容的驱动程序可能会干扰截图工具。来自其他应用程序的干扰:其他正在运行的应用程序可能与截图工具冲突。证书已过期:升级过程中的错误可能会导致此issu简单的解决方案这些适合大多数用户,不需要任何特殊的技术知识。1.更新窗口和Microsoft应用商店应用程

jquery隐藏select元素的方法:1、hide()方法,在HTML页面中引入jQuery库,可以使用不同选择器来隐藏select元素,ID选择器将selectId替换为你实际使用的select元素的ID;2、css()方法,使用ID选择器选择需要隐藏的select元素,使用css()方法将display属性设置为none,并将selectId替换为select元素的ID。

第1部分:初始故障排除步骤检查苹果的系统状态:在深入研究复杂的解决方案之前,让我们从基础知识开始。问题可能不在于您的设备;苹果的服务器可能会关闭。访问Apple的系统状态页面,查看AppStore是否正常工作。如果有问题,您所能做的就是等待Apple修复它。检查您的互联网连接:确保您拥有稳定的互联网连接,因为“无法连接到AppStore”问题有时可归因于连接不良。尝试在Wi-Fi和移动数据之间切换或重置网络设置(“常规”>“重置”>“重置网络设置”>设置)。更新您的iOS版本:

Laravel集合中的Where方法实用指南在Laravel框架的开发过程中,集合(Collection)是一个非常有用的数据结构,它提供了丰富的方法来操作数据。其中,Where方法是一个常用的筛选方法,能够根据指定条件来过滤集合中的元素。本文将介绍Laravel集合中Where方法的使用,通过具体的代码示例来演示其用法。1.基本用法Where方法的

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code<form name="myform"

因为select可以使开发者在同时等待多个文件缓冲区,可减少IO等待的时间,能够提高进程的IO效率。select()函数是IO多路复用的函数,允许程序监视多个文件描述符,等待所监视的一个或者多个文件描述符变为“准备好”的状态;所谓的”准备好“状态是指:文件描述符不再是阻塞状态,可以用于某类IO操作了,包括可读,可写,发生异常三种。select是一个计算机函数,位于头文件#include。该函数用于监视文件描述符的变化情况——读写或是异常。1.select函数介绍select函数是IO多路复用的函

Laravel集合中如何使用Where方法Laravel是一个流行的PHP框架,它提供了丰富的功能和工具,方便开发者快速构建应用程序。其中,集合(Collection)是Laravel中一个非常实用和强大的数据结构,开发者可以使用集合对数据进行各种操作,如过滤、映射、排序等。在集合中,Where方法是一个常用的方法,用于根据指定的条件过滤集


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

禅工作室 13.0.1
功能强大的PHP集成开发环境

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

记事本++7.3.1
好用且免费的代码编辑器

Atom编辑器mac版下载
最流行的的开源编辑器