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即可建立表格結構
[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;"
開啟mysql,使用source mysql.sql即可建立表格架構
主要設定zend Framework連接mysql
// Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : '<strong>development</strong>')); //修改成测试环境
<?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; } } } ?>
執行指令:zf create model page
會自動產生一個models/Page.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"; } }
檔
<?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; } }
news 會自動產生controllers/NewsController.php
<?php echo "<h3>".$this->News[0]['title']."</h3>"; echo $this->News[0]['body']; //echo $this->name; if($this->News) { /*echo "<ul>"; // print_r($this->News); foreach($this->News as $val) { echo "<li>"."<u>".$val['title']."</u>"."</li>"; } echo "</ul>"; */ echo "<ul class = 'listNews'>"; echo $this->partialLoop('row_pages.phtml', $this->News); echo "</ul>"; } ?>
執行指令: zf create controller page 和zf create action detail page
會自動產生 controllers/PageController.H
會自動產生 controllers/PageController. views/scripts/news/index.phtml
<li> <a href = "/page/detail/id/<?php echo $this->id; ?>"><?php echo $this->title; ?></a> 发表时间: <?php echo date('Y-m-d', $this->createtime); ?> </li>
/views/scripts/row_pages.phtml
<?php echo "<h2>".$this->page['title']."</h2>"; echo "发表:".date('Y-m-d', $this->page['createtime']).""; echo "<hr/>"; echo $this->page['body']; ?>

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++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。

Laravel集合中的Where方法實用指南在Laravel框架的開發過程中,集合(Collection)是一個非常有用的資料結構,它提供了豐富的方法來操作資料。其中,Where方法是常用的篩選方法,能夠根據指定條件來過濾集合中的元素。本文將介紹Laravel集合中Where方法的使用,透過具體的程式碼範例來示範其用法。 1.基本用法Where方法的

使用golang進行SelectChannelsGo並發式程式設計的非同步處理方法引言:並發式程式設計是現代軟體開發中的重要領域,它可以有效地提高應用程式的效能和回應能力。在Go語言中,使用Channels和Select語句可以簡單而有效率地實現並發程式設計。本文將介紹如何使用golang進行SelectChannelsGo並發式程式設計的非同步處理方法,並提供具體的

jQuery是一個受歡迎的JavaScript函式庫,可以用來簡化DOM操作、事件處理、動畫效果等。在web開發中,常常會遇到需要對select元素進行改變事件綁定的情況。本文將介紹如何使用jQuery實作對select元素改變事件的綁定,並提供具體的程式碼範例。首先,我們需要使用標籤來建立一個包含選項的下拉式選單:

第1部分:初始故障排除步驟檢查蘋果的系統狀態:在深入研究複雜的解決方案之前,讓我們先從基礎知識開始。問題可能不在於您的設備;蘋果的伺服器可能會關閉。造訪Apple的系統狀態頁面,查看AppStore是否正常運作。如果有問題,您所能做的就是等待Apple修復它。檢查您的網路連接:確保您擁有穩定的網路連接,因為「無法連接到AppStore」問題有時可歸因於連接不良。嘗試在Wi-Fi和行動數據之間切換或重置網路設定(「常規」>「重置」>「重置網路設定」>設定)。更新您的iOS版本:

因為select可以讓開發者同時等待多個檔案緩衝區,可減少IO等待的時間,能夠提高進程的IO效率。 select()函數是IO多路復用的函數,允許程式監視多個檔案描述符,等待所監視的一個或多個檔案描述符變成「準備好」的狀態;所謂的」準備好「狀態是指:檔案描述子不再是阻塞狀態,可以用於某類IO操作了,包括可讀,可寫,發生異常三種。 select是一個電腦函數,位於頭檔#include。此函數用於監視文件描述符的變化情況-讀寫或是異常。 1.select函數介紹select函數是IO多工的函
