This article refers to "PHP top framework Zendframe Development Combat" fourth chapter content, and complete realization ...
Download the CSS file you used first: http://download.csdn.net/download/unityoxb/4058802
After decompression, the default and common two files are copied to the Public/skins directory;
1. database files used Mysql.sql
CREATE table if not EXISTS ' core_pages ' ( ' id ' int ($) unsigned not NULL auto_increment comment ' page unique ID ', ' cid ' int unsigned NOT NULL default ' 0 ' comment ' class id ', ' uid ' int (ten) unsigned NOT null default ' 0 ' comment ' User ID ', ' Ti tle ' varchar (255) NOT null comment ' page title ', ' body ' text not null comment ' content ', ' status ' tinyint (4) NOT NULL default ' 1 ' comment ' is published ', ' createtime ' int (one) not null default ' 0 ' comment ' Create page time ', ' updatetime ' int (one) NOT null Def Ault ' 0 ' comment ' modified page time ', ' comment ' tinyint (4) NOT null default ' 0 ' comment ' page comment function ', ' start ' tinyint (4) Not Nu ll default ' 0 ' comment ' page level ', ' top ' tinyint (4) NOT null default ' 0 ' comment ' pinned ', primary key (' ID ')) engine=inn ODB default Charset=utf8;
Open MySQL, use source mysql.sql to create table structure
2. Configuration Application.ini file (hahacom/applicaton/configs)
Main configuration Zend Framework connection MySQL
[development:production]phpsettings.display_startup_errors = 1phpsettings.display_errors = 1resources.frontcontroller.params.displayexceptions = 1resources.db.adapter = "Pdo_mysql" Resources.db.params.host = "localhost" resources.db.params.username = "root" Resources.db.params.password = "root" Resources.db.params.dbname = " Test "-This is the data name resources.db.isDefaultTableAdapter =" TRUE "resources.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'); Modify into a test environment
4, create the article display model (model main storage data model similar to JavaBean, or get data from the database and save in memory)
Execute command: ZF Create model page
A models/page.php file is automatically generated
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. ' =? ', $valu e); }//$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. Create Controller
Execute command: ZF Create controller news will automatically generate controllers/newscontroller.php
1, ' comment ' =>1); $newsStar = $modelPage->getpage ($where); Print_r ($newsStar); $this->view->news = $newsStar; $this->view->name = "hahaha"; }}
Execute command: ZF Create controller page and ZF Create action detail page
will automatically generate 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. Next CREATE View File
/views/scripts/news/index.phtml
". $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 "
";}? >
/views/scripts/row_pages.phtml
ID;?> ">
title?> publish time:
createtime)?>
/views/scripts/page/detail.phtml
". $this->page[' title ']."; echo "Published:". Date (' y-m-d ', $this->page[' Createtime ']). ""; echo "
"; echo $this->page[' body '];? >
Run:
Click the link:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes PHP using Zendframework programming examples, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.