2

对不起,我知道有很多关于这方面的教程,我试过但没有奏效。

我在 c: 中安装了 WAMP。它的文档根目录是 d:/Sites/Wamp。我已经能够从那里加载常规的 html、php、wordpress 和 Code Igniter。

使用 Code Igniter,这非常容易,因为我只需将库复制粘贴到 d:/sites/Wamp 文件夹并配置数据库。

使用 Zend 框架,我想做一些类似的事情,我只需将一些文件复制到 Wamp 文件夹中。那可能吗?我现在想避免使用 Zend Tool。可以通过教程或要复制的文件为我指明正确的方向。

4

3 回答 3

2

如果由于某种原因你不想使用 Zend_Tool 这里是默认的基本应用程序结构:

project
|-- application
|   |-- Bootstrap.php
|   |-- configs
|   |   `-- application.ini
|   |-- controllers
|   |   |-- ErrorController.php
|   |   `-- IndexController.php
|   |-- models
|   `-- views
|       |-- helpers
|       `-- scripts
|           |-- error
|           |   `-- error.phtml
|           `-- index
|               `-- index.phtml
|-- library
|   `--Zend //zend framework  goes here ***
|-- public
|   |-- .htaccess
|   `-- index.php
`-- tests
    |-- application
    |   `-- bootstrap.php
    |-- library
    |   `-- bootstrap.php
    `-- phpunit.xml

在 Zend Framework 下载中,您将找到该library文件夹​​,并在其中找到该Zend文件夹​​。将整个 Zend 文件夹复制到,project/library这样它最终会成为project/library/Zend/

您的默认设置.htaccess看起来像并且属于公用文件夹:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

在您的公用文件夹中也将是您的index.php,并且看起来像:

<?php
//the next line is optional and is only to remove the index.php from the url
//$_SERVER["REQUEST_URI"] = str_replace('index.php', '', $_SERVER["REQUEST_URI"]);
// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// 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(APPLICATION_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'
);
$application->bootstrap()
            ->run();

随意project/application/configs/保存application.ini文件,一开始看起来像:

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

[staging : production]

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

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

默认Bootstrap.php看起来像:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
}

默认indexController看起来像:

class IndexController extends Zend_Controller_Action
{

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

    public function indexAction()
    {
        // action body
    }
}

最后默认的错误控制器看起来像:

class ErrorController extends Zend_Controller_Action
{

    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');

        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:

                // 404 error -- controller or action not found
                $this->getResponse()->setHttpResponseCode(404);
                $this->view->message = 'Page not found';
                break;
            default:
                // application error
                $this->getResponse()->setHttpResponseCode(500);
                $this->view->message = 'Application error';
                break;
        }

        $this->view->exception = $errors->exception;
        $this->view->request   = $errors->request;
    }
}

现在您应该能够通过 url 访问您的项目,http://localhost/project/public所有对 Zend Framework 应用程序的请求都将通过index.php.

我真的推荐Zend_Tool,它是有原因的。

如果您需要更多...RTM 所有这些都在文档中。

于 2013-05-09T07:36:54.323 回答
0

确保您在 apache 中设置了一个虚拟主机,这就是我在 WAMP 安装上的一个测试环境:

<VirtualHost *:80>
    ServerName zend.local
    DocumentRoot "c:/wamp/www/zend/public"
    SetEnv APPLICATION_ENV "development"
    <Directory "c:/wamp/www/zend/public">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

显然我还在我的主机文件中添加了一行将 zend.local 指向 127.0.0.1

于 2013-05-08T17:44:19.507 回答
0

我建议您遵循 Rob Allen 的教程,您可以在http://akrabat.com/zend-framework-tutorial/找到该教程。这将建议使用 Zend Tool 来设置骨架应用程序,但既然您已经说过您不想这样做,您可以从他的网站下载完成的代码并阅读教程以了解它是如何组合在一起的。

于 2013-05-09T00:17:40.293 回答