Bootstrap 中的 Zend setHelperPath

发布于 2024-11-06 18:11:25 字数 1669 浏览 3 评论 0原文

在 Zend 框架中,如何使用 bootstrap.php 文件中的 setHelperPath 方法使框架可以访问“My_View_Helper_Test”(假设 Helper 绝对路径是常量“MY_PATH”)?

的index.php

//identify the location of th application dir in respect to 
//the botstrap file's location, and configure PHP's include_path to
//include the library directory's location

define('APPLICATION_PATH',realpath(dirname(__FILE__).'/../application'));
set_include_path(APPLICATION_PATH.'/../library'.PATH_SEPARATOR.get_include_path());


//give the zend framework the ability to load classes on demand,
//as you request them,rather than having to deal with require() statements.

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

//retrieve the BOOTSTRAP file
try
{
require'../application/bootstrap.php';  
}
catch(Exception $exception)
{
printf('Could not locate bootstrap.php');
exit(1);    
}

//start using the front controller in order to route all requests
Zend_Controller_Front::getInstance()->dispatch();

我的bootstrap.php

//configure the site environment status

defined('APPLICATION_ENVIRONMENT')or define('APPLICATION_ENVIRONMENT','development');

//invoke the front controller
$frontController=Zend_Controller_Front::getInstance();

//identify the location of the controller directory
$frontController->setControllerDirectory(APPLICATION_PATH.'/controllers');

//create the env parameter so you can later access the environment
//status within the application

$frontController->setParam('env',APPLICATION_ENVIRONMENT);

//clean up all allocated script resources
unset($frontController);

谢谢卢卡

In Zend framework how could I use the setHelperPath method in my bootstrap.php file to make "My_View_Helper_Test" accessible to the framework (let's say the Helper absolute path is the constant 'MY_PATH')?

My index.php

//identify the location of th application dir in respect to 
//the botstrap file's location, and configure PHP's include_path to
//include the library directory's location

define('APPLICATION_PATH',realpath(dirname(__FILE__).'/../application'));
set_include_path(APPLICATION_PATH.'/../library'.PATH_SEPARATOR.get_include_path());


//give the zend framework the ability to load classes on demand,
//as you request them,rather than having to deal with require() statements.

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

//retrieve the BOOTSTRAP file
try
{
require'../application/bootstrap.php';  
}
catch(Exception $exception)
{
printf('Could not locate bootstrap.php');
exit(1);    
}

//start using the front controller in order to route all requests
Zend_Controller_Front::getInstance()->dispatch();

My bootstrap.php

//configure the site environment status

defined('APPLICATION_ENVIRONMENT')or define('APPLICATION_ENVIRONMENT','development');

//invoke the front controller
$frontController=Zend_Controller_Front::getInstance();

//identify the location of the controller directory
$frontController->setControllerDirectory(APPLICATION_PATH.'/controllers');

//create the env parameter so you can later access the environment
//status within the application

$frontController->setParam('env',APPLICATION_ENVIRONMENT);

//clean up all allocated script resources
unset($frontController);

Thanks

Luca

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

椵侞 2024-11-13 18:11:25

首先,您应该拥有这样的自举课程:
http://framework.zend.zend.com/manual/enual/en/en/en/zend.application.application.application 。

    /**
 * Initializes the view
 *
 * @return Zend_View A view object
 */
protected function _initView()
{
    // Initialize view
    $view = new Zend_View();

    // Add view helper path
    $view->addHelperPath(
        MY_PATH,
        'My_View_Helper'
    );

    // Add the view to the ViewRenderer
    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
        'ViewRenderer'
    );
    $viewRenderer->setView($view);

    // Return it, so that it can be stored by the bootstrap
    return $view;
}

First of all you should have a bootstrap class like this:
http://framework.zend.com/manual/en/zend.application.examples.html

Then within your bootstrap class, you would add a method to initialize the view and add the view helper path:

    /**
 * Initializes the view
 *
 * @return Zend_View A view object
 */
protected function _initView()
{
    // Initialize view
    $view = new Zend_View();

    // Add view helper path
    $view->addHelperPath(
        MY_PATH,
        'My_View_Helper'
    );

    // Add the view to the ViewRenderer
    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
        'ViewRenderer'
    );
    $viewRenderer->setView($view);

    // Return it, so that it can be stored by the bootstrap
    return $view;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文