Zend Framework

一.配置:

1.php.ini 开启PDO及PDO相关数据库引擎

extension=php_pdo_mysql.dll

2.http.conf 开启rewrite模块
  2.1

LoadModule rewrite_module modules/mod_rewrite.so

 2.2 并识别.htaccess功能

<Directory />
    Options FollowSymLinks
    AllowOverride ALL
    Order deny,allow
    Deny from all
    Satisfy all
</Directory>
...
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride ALL
...
# CGI directory exists, if you have that configured.
#
<Directory "E:/www/Apache2.2/cgi-bin">
    AllowOverride All
    Options None
    Order allow,deny
    Allow from all
</Directory>

3.配置虚拟主机                        //虚拟主机配置非必要,麻烦...

   3.1 http.conf

# Virtual hosts 启动虚拟主机的配置
Include conf/extra/httpd-vhosts.conf

   3.2 /apache/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
     DocumentRoot "E://www/myweb.com/public"
     ServerName myweb.com
     <Directory />
     Options FollowSymLinks
     AllowOverride None
     Order allow,deny
     Allow from all
     </Directory>
</VirtualHost>

在windows的host文件里面加上

127.0.0.1       myweb.com

配置错误日志

可以在php.ini设置

error_log="E:\www\php_errors.log" 能查看系统的错误日志

================================================================================
================================================================================

创建项目

进入到Zend FrameWork源码包,在bin目录下使用 zf.bat 生成ZF工程 zf.bat create project (项目路径)

之后把源码包里面的library/Zend 复制到项目文件对应的library文件夹下

================================================================================
================================================================================

数据库配置
/application/configs/application.ini
后面加上      注:不同写法的数据库配置文件,其数据库适配器书写也不一样,特注:数据库配置文件后面的说明不要带上

[mysql]                         //节名自己随意取
db.adapter = PDO_MYSQL          //请开启PDO扩展
db.params.host = localhost      //Mysql主机地址
db.params.username = root       //用户名
db.params.password = root       //密码
db.params.dbname = ceshi        //数据库

 初始化数据库适配器
 在 ./application/controllers/下 创建 BaseController.php 用于数据库连接的 父类

<?php
class BaseController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
        /**
         * 初始化数据库适配器
         */
        //从应用程序的路径找到【数据库配置文件】
        $url = constant("APPLICATION_PATH") . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . 'application.ini';
        //下面的 mysql 指的是 数据库配置文件application.ini中数据库配置的节点名,指定读取哪一节
        $dbconfig = new Zend_Config_Ini( $url, "mysql");
        //初始化数据库工厂
        $db = Zend_Db :: factory($dbconfig->db);
        $db->query('SET NAMES UTF8');
        Zend_Db_Table::setDefaultAdapter($db);
    }
}

数据库测试:

在./application/models/ 下创建 GoodsMod.php

<?php

class GoodsMod extends Zend_Db_Table{
    protected $_name = 'ecs_goods';  //表名
    protected $_primary = 'goods_id';//表的主键
}

?>

./application/controllers/IndexController.php 修改为

<?php

require_once(APPLICATION_PATH.'/models/GoodsMod.php');
require_once(APPLICATION_PATH.'/controllers/BaseController.php');

class IndexController extends BaseController
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }

    public function textAction()
    {
         $GoodMod = new GoodsMod();
         $res = $GoodMod->fetchAll()->toArray();
         echo "<pre>";
         print_r($res);
         echo "</pre>";
         exit;
    }
}



================================================================================
================================================================================

 Digitalus CMS 这个开源模板适合学习 ZF   digitalus_1.8 错误修改

date_default_timezone_set('Asia/Shanghai');

原文地址:https://www.cnblogs.com/zhiqixue/p/2811726.html