Php 为了我的生命,我可以';我不知道如何设置Zend框架

Php 为了我的生命,我可以';我不知道如何设置Zend框架,php,zend-framework,Php,Zend Framework,对不起,我知道有很多关于这个的教程,我试过了,但没有成功 我已在c:中安装WAMP。它的文档根是d:/Sites/Wamp。我已经能够从那里加载常规html、php、wordpress和CodeIgniter 使用CodeIgniter非常简单,因为我只需将库复制粘贴到d:/sites/Wamp文件夹并配置数据库 对于Zend框架,我想做一些类似的事情,只需将一些文件复制到Wamp文件夹中。可能吗?我现在不想使用Zend工具。请给我一个指导或复制哪些文件,好吗?请确保您在apache中设置了一个

对不起,我知道有很多关于这个的教程,我试过了,但没有成功

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

使用CodeIgniter非常简单,因为我只需将库复制粘贴到d:/sites/Wamp文件夹并配置数据库


对于Zend框架,我想做一些类似的事情,只需将一些文件复制到Wamp文件夹中。可能吗?我现在不想使用Zend工具。请给我一个指导或复制哪些文件,好吗?

请确保您在apache中设置了一个虚拟主机这是我在WAMP安装中为just a test Environment准备的:

<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>

ServerName zend.local
DocumentRoot“c:/wamp/www/zend/public”
SetEnv应用程序_ENV“开发”
DirectoryIndex.php
允许超越所有
命令允许,拒绝
通融

显然,我还在宿主文件中添加了一行代码,将zend.local指向127.0.0.1

我建议您遵循Rob Allen的教程,您可以在上找到。这将建议使用Zend工具来设置skeleton应用程序,但既然你已经说过你不想这样做,你可以从他的网站下载完成的代码,并通读教程,看看它是如何组合起来的。

如果出于某种原因你不想使用Zend_工具,这里是默认的基本应用程序结构:

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下载中,您将找到
文件夹,在那里您将找到
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();
[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
{
}
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;
    }
}
默认的
indexController
如下所示:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
}
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;
    }
}
最后,默认错误控制器如下所示:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
}
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_工具
,它的构建是有原因的


如果您还需要…RTM,所有这些都可以从文档中找到。

如果您使用CodeIgniter,为什么要使用Zend?我知道环境设置有时比实际问题更困难。在经历了同样的场景(但有了Python、ROR等等)之后,我搬到了Ubuntu,生活变得简单了一些。是的,我没有注意到“这里有常规的html、php、wordpress和代码点火器”。来自Zend的Wordpress?我之前的评论仍然有效。你在Apache中为它创建了虚拟主机吗?不,我不是指Zend。我的意思是,我能够让html、php、wordpress和CodeIgniter在我的开发计算机上与我的WAMP堆栈一起工作。当时我甚至没有试过Zend。我之所以想使用Zend框架,是因为我仍在学习web开发,我想接触所有主要的框架。另外,我不熟悉虚拟主机。阅读维基百科,我想我明白它是什么。每当我开始使用新框架时,我一直在清除我的D:/Sites/Wamp文件夹。如果我错了,请纠正我,但我认为这样做是为了防止我的开发计算机上有多个站点,它们可能会冲突。这是非常重要的信息,我将在未来创建虚拟主机。然而,由于每次我开始一个新网站时都会清除我的c:/wamp/www文件夹,所以我认为这对我现在没有帮助。我的意思是,使用CodeIgniter,我只需将下载的内容复制粘贴到www文件夹,就可以立即获得一个欢迎页面,并从中学习。有了Zend框架,有可能做类似的事情吗?我绝对不是Zend专家,我刚刚下载并玩了几次。我个人是Yii框架的忠实粉丝。但我第一次和Zend一起学习了一个教程,我必须做一些设置工作,这不仅仅是下载并开始使用它。最初,我正在考虑放弃它,转而学习Yii、CakePHP、Symphony等。无论哪种方式(Zend或Yii或其他方式),你最好的选择是找到一个合适的教程,并在第一次学习它。好的,我下班回家后会试试的。我最终会使用这个工具,但我只需要知道我能够在没有它的情况下设置它,并看看如何手动至少执行一次。然后我才能真正理解这个工具的真正功能。