搜尋
首頁後端開發php教程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即可建立表格架構




2.設定application.ini檔案(hahacom/applicaton/configs)


主要設定zend Framework連接mysql

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : '<strong>development</strong>')); //修改成测试环境
3、public/index.php


<?php class Application_Model_Page
{
   protected $_name = &#39;core_pages&#39;;
   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;
      }

   }
}

?>
4、建立文章主要展示文章展示javabean,或從資料庫取得資料並儲存在記憶體中)


執行指令: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(&#39;top&#39;=>1, 'comment'=>1);
        $newsStar = $modelPage->getPage($where);
        //print_r($newsStar);
        $this->view->News = $newsStar;
        //$this->view->name = "hahaha"; 
    }


}
5、建立一個modtroller



<?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、建立一個controller

news   會自動產生controllers/NewsController.php

<?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 "
    "; echo $this->partialLoop('row_pages.phtml', $this->News); echo "
"; } ?>

執行指令: zf create controller page 和zf create action detail page
會自動產生 controllers/PageController.H

會自動產生 controllers/PageController. views/scripts/news/index.phtml


  • title; ?> 发表时间: createtime); ?>

  • /views/scripts/row_pages.phtml

    <?php echo "<h2>".$this->page['title']."";
       echo "发表:".date('Y-m-d', $this->page['createtime'])."";
       echo "<hr>";
       echo $this->page['body'];
    ?>
    
    /views/scripts/page/detail.p 點擊連結:

    🎜🎜🎜版權聲明:本文為部落客原創文章,未經部落客允許不得轉載。 🎜🎜 🎜 以上就介紹了php利用zendframework程式設計實例,包含了面向的內容,希望對PHP教學有興趣的朋友有幫助。 🎜 🎜 🎜
    陳述
    本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
    华为GT3 Pro和GT4的差异是什么?华为GT3 Pro和GT4的差异是什么?Dec 29, 2023 pm 02:27 PM

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

    修复:截图工具在 Windows 11 中不起作用修复:截图工具在 Windows 11 中不起作用Aug 24, 2023 am 09:48 AM

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

    jquery如何隐藏select元素jquery如何隐藏select元素Aug 15, 2023 pm 01:56 PM

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

    如何修复无法连接到iPhone上的App Store错误如何修复无法连接到iPhone上的App Store错误Jul 29, 2023 am 08:22 AM

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

    Laravel 集合中的 Where 方法实用指南Laravel 集合中的 Where 方法实用指南Mar 10, 2024 pm 04:36 PM

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

    php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决Jun 13, 2016 am 10:23 AM

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

    linux要用select的原因是什么linux要用select的原因是什么May 19, 2023 pm 03:07 PM

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

    Laravel 集合中如何使用 Where 方法Laravel 集合中如何使用 Where 方法Mar 10, 2024 pm 10:21 PM

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

    See all articles

    熱AI工具

    Undresser.AI Undress

    Undresser.AI Undress

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

    AI Clothes Remover

    AI Clothes Remover

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

    Undress AI Tool

    Undress AI Tool

    免費脫衣圖片

    Clothoff.io

    Clothoff.io

    AI脫衣器

    AI Hentai Generator

    AI Hentai Generator

    免費產生 AI 無盡。

    熱門文章

    R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
    3 週前By尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O.最佳圖形設置
    3 週前By尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O.如果您聽不到任何人,如何修復音頻
    3 週前By尊渡假赌尊渡假赌尊渡假赌

    熱工具

    mPDF

    mPDF

    mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

    SecLists

    SecLists

    SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

    禪工作室 13.0.1

    禪工作室 13.0.1

    強大的PHP整合開發環境

    Safe Exam Browser

    Safe Exam Browser

    Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

    PhpStorm Mac 版本

    PhpStorm Mac 版本

    最新(2018.2.1 )專業的PHP整合開發工具