php项目zend无法运行,php – Zend Framework项目,不使用Zend_Application

我把它扔到了一起:

转载如下以完成.没有经过测试,只是我认为它(!)的一些想法可能会起作用.现在我已经了解了一下,我对Zend_Application,它的引导类以及可配置/可重用的应用程序资源有了更多的了解. 😉

// Do your PHP settings like timezone, error reporting

// ..

// Define path to application directory

defined('APPLICATION_PATH')

|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/_zf/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(),

)));

// Get autoloading in place

require_once 'Zend/Loader/Autoloader.php';

$autoloader = Zend_Loader_Autoloader::getInstance();

// Any additional configs to autoloader, like custom autoloaders

// Read config

$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);

// bootstrap resources manually:

// * create db adapter

// * create resource autoloaders with the mappings you need

// * etc

// Get the singleton front controller

$front = Zend_Controller_Front::getInstance();

// Set controller directory

$front->setControllerDirectory(APPLICATION_PATH . '/controllers');

// Or set module directory

$front->setModuleDirectory(APPLICATION_PATH . '/modules');

// Other front config, like throw exceptions, etc.

// ...

//

// Create a router

$router = new Zend_Controller_Router_Rewrite();

// Add routes to the router

$router->addRoute('myRoute', new Zend_Controller_Router_Route(array(

// your routing params

)));

// More routes...

// Alternatively, the routes can all be in an xml or ini file and you can add

// them all at once.

// Tell front to use our configured router

$front->setRouter($router);

// Add an plugins to your $front

$front->registerPlugin(new My_Plugin());

// other plugins...

// Dispatch the request

$front->dispatch();

可能还有一些View / ViewRenderer要做的事情.但正如其他地方所指出的那样,ViewRenderer会带来非常重要的性能影响.如果性能问题,那么您将要禁用ViewRenderer并使用$this-> view-> render(‘my / view-script.phtml’)让您的动作控制器调用自己的渲染

当您调用$front-> dispatch()时,将自动创建$request和$response对象.如果你想在bootstrap上做一些特定的事情 – 比如在响应的Content-Type标题中设置charset – 那么你可以自己创建你的请求/响应对象,做你想做的事,然后将它附加到前面使用$front-> setResponse($response);对于请求对象也是如此.

虽然我看到我的示例使用Zend_Loader_Autoloader和Zend_config_Ini,但Padraic指出这会导致性能下降.下一步是通过使用数组进行配置,从框架中剥离require_once调用,注册不同的自动加载器等来解决这些问题,为读者留下一个练习…… 😉

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值