最新zendframework1.11使用

1、下载zf最新版Zend Framework- Downloads- Downloads

2、首先进入cmd,命令行窗口模式。
直接打下面的命令,
C:\Documents and Settings\Administrator>E:\PHP\开源框架\ZendFramework-1.11.3\ZendFramework-1.11.3\bin\zf.bat create project D:\temp\zflearn
3、C:\Documents and Settings\Administrator>d:  
进入D盘
D:\>cd temp\zflearn
进入网站的目录
D:\temp\zflearn>E:\PHP\开源框架\ZendFramework-1.11.3\ZendFramework-1.11.3\bin\zf.bat create module vote
创建vote模型
在D:\temp\zflearn\application\modules\vote\controllers下创建LoginController.php控制器
同时也在D:\web\zf\application\modules\vote\views\scripts下生成视图 login\index.phtml
D:\temp\zflearn>E:\PHP\开源框架\ZendFramework-1.11.3\ZendFramework-1.11.3\bin\zf.bat create controller login 1 vote
如果后面不加1 vote
则创建在D:\temp\zflearn\application\controllers
D:\temp\zflearn\application\views\scripts下生成视图 login\index.phtml
拷贝zend库
将E:\PHP\开源框架\ZendFramework-1.11.3\ZendFramework-1.11.3\library 下的zend文件夹拷贝到
在D:\temp\zflearn\library下

附:网站整个目录不能有空格不然生成不成功

index.php代码

<?php

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
defined('WEBROOT_PATH')
    || define('WEBROOT_PATH', realpath(dirname(__FILE__)));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(WEBROOT_PATH . '/library'),
    get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);

//$config=new Zend_Config_Ini(APPLICATION_PATH.'/configs/application.ini',null,true);
//$db=Zend_Db::factory($config->general-&gt;db-&gt;adapter,$config-&gt;general-&gt;db-&gt;params-&gt;toArray());
//Zend_Db_Table::setDefaultAdapter($db);
$application-&gt;bootstrap()
            -&gt;run();

?&gt;

Bootstrap.php

<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initAutoload()
    {
        $loader = new Zend_Application_Module_Autoloader(array(
            'namespace' => '',
            'basePath' =&gt; APPLICATION_PATH));
        $loader-&gt;addResourceType('form', 'forms', 'Form')
                -&gt;addResourceType('model', 'models', 'Model')
                -&gt;addResourceType('dbtable', 'models/DbTable', 'Model_DbTable');
        // $loader-&gt;addResourceType('model', 'models',null);
        return $loader;       
    }
    protected function _initDB()
    {
        $options = $this-&gt;getOption('resources');
        $options = $options['db'];
        $resources = $this-&gt;getPluginResource('db');
        $db = $resources-&gt;getDbAdapter();
        Zend_Db_Table::setDefaultAdapter($db);
        //Zend_Registry::set('dbAdapter',$db);
        //Zend_Registry::set('dbprefix',$options['params']['prefix']);
    }
}

?&gt;

application.ini

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
includePaths.models = APPLICATION_PATH "/models/"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.db.adapter =PDO_MYSQL
resources.db.params.host ="192.168.0.1"
resources.db.params.username ="root"
resources.db.params.password ="123456"
resources.db.params.dbname ="zflearn"
resources.db.params.prefix =""
resources.db.isDefaultTableAdapter = TRUE
resources.db.params.driver_options.1002    = "SET NAMES UTF8;"
[staging : production]

[testing : production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0

[development : production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
resources.frontController.params.displayExceptions = 1

你可能感兴趣的:(职场,zf,休闲,zendframework)