php利用zendframework编程实例
本文章参考《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教程有兴趣的朋友有所帮助。

热AI工具

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

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

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

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

热门文章

热工具

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

SublimeText3汉化版
中文版,非常好用

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

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

许多用户在选择智能手表的时候都会选择的华为的品牌,其中华为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。

使用golang进行SelectChannelsGo并发式编程的异步处理方法引言:并发式编程是现代软件开发中的一个重要领域,它可以有效地提高应用程序的性能和响应能力。在Go语言中,使用Channels和Select语句可以简单而高效地实现并发编程。本文将介绍如何使用golang进行SelectChannelsGo并发式编程的异步处理方法,并提供具体的

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

jQuery是一个流行的JavaScript库,可以用来简化DOM操作、事件处理、动画效果等。在web开发中,经常会遇到需要对select元素进行改变事件绑定的情况。本文将介绍如何使用jQuery实现对select元素改变事件的绑定,并提供具体的代码示例。首先,我们需要使用标签来创建一个包含选项的下拉菜单:

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

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