简体   繁体   English

require_once(Zend / Application.php):使用zend框架时无法打开流

[英]require_once(Zend/Application.php): failed to open stream when using zend framework

I am a new user to zend framework and i tried the other solutions given in stack overflow for similar questions. 我是zend Framework的新用户,我尝试了堆栈溢出中给出的其他解决方案来解决类似问题。

This is my index.php 这是我的index.php

<?php
date_default_timezone_set('UTC');
// 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(); 

When i echo set_include_path, this is the response i got, 当我回显set_include_path时,这是我得到的响应,

:.:/usr/lib64/php :。:/ usr / lib64 / php

Do i have to install zend framework in my new Cent OS ? 我必须在新的Cent OS中安装zend framework吗?

My library folder is, in the same directory the index.php reside. 我的库文件夹是index.php所在的目录。

/home/eat/public_html/index.php /home/eat/public_html/library /home/eat/public_html/library/Zend /home/eat/public_html/index.php / home / eat / public_html / library / home / eat / public_html / library / Zend

Update.. 更新..

When i hardcoded the path as, set_include_path('/home/eat/public_html/library/'); 当我将路径硬编码为set_include_path('/ home / eat / public_html / library /');

I started getting a new error. 我开始遇到新错误。 which is, 就是

    Warning: require_once(Zend/Loader/Autoloader.php): failed to open stream: No such file or directory in /home/eat/public_html/library/Zend/Application.php on line 80

    Fatal error: require_once(): Failed opening required 'Zend/Loader/Autoloader.php' (include_path='/home/eat/public_html/library/') in /home/eat/public_html/library/Zend/Application.php on line 80

**Update 2**

Fatal error: Uncaught exception 'Zend_Application_Bootstrap_Exception' with message 'Resource matching "multidb" not found' in /home/eat/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php:691 Stack trace: #0 /home/eat/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(626): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('multidb') #1 /home/eat/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(583): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap('multidb') #2 /home/eat/public_html/application/Bootstrap.php(58): Zend_Application_Bootstrap_BootstrapAbstract->bootstrap('multidb') #3 /home/eat/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(666): Bootstrap->_initApplication() #4 /home/eat/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(619): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('application') #5 /home/eat/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(583): Z in /home/eat/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php on line 691

Application.ini Application.ini

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

eat.application.base.url = "eat.com"
eat.application.admin.url = "admin.eat.com"
eat.application.api.url = "api.eat.com"

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.prefixDefaultModule = "1"

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

autoloaderNamespaces[] = "Eat_"

resources.modules = ""

phpSettings.date.timezone = "GMT"

eat.application.salt = "sd876fs89df";
resources.view[] =
resources.view.helperPath.Eat_View_Helper = APPLICATION_PATH "/../library/Eat/View/Helper"

;;; Databases


;;;;; Layouts

resources.layout.layoutPath = APPLICATION_PATH "/views/layouts"
resources.layout.layout = web/web

nexva.applicaiton.fileUploadDirectory = APPLICATION_PATH "/../files"

;;;; ReCaptcha ;;;;
recaptcha.private_key = 6LfL7rsSAAAAAKgtKWsMk4hmA2DSVq0ODcyJFRjs
recaptcha.public_key = 6LfL7rsSAAAAANiaZOQN7LOoCGAXh29rHTZPRoVa

[staging : production]
eat.application.base.url = "eat.com"
eat.application.admin.url = "admin.eat.com"
eat.application.api.url = "api.eat.com"

;;; Databases
resources.multidb.default.adapter       = mysqli
resources.multidb.default.host          = "localhost"
resources.multidb.default.username      = "eat"
resources.multidb.default.password      = "eat"
resources.multidb.default.dbname        = "eat_main"
resources.multidb.default.default       = true

[development : production]
eat.application.base.url = "eat.com"
eat.application.admin.url = "admin.eat.com"
eat.application.api.url = "api.eat.com"

;;; Databases
resources.multidb.default.adapter       = mysqli
;resources.multidb.default.host          = "192.168.1.253"
resources.multidb.default.host            = "localhost"
resources.multidb.default.username      = "eat"
resources.multidb.default.password      = "eat"
resources.multidb.default.dbname        = "eat_main"
resources.multidb.default.default       = true

[development-alt : development]

Update 3 更新3

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    public function __construct($application)
    {
        parent::__construct($application);
    }

    protected function _initAutoload()
    {

        Zend_Controller_Action_HelperBroker::addPrefix('Eat_Controller_Action_Helper');

    $autoloader = new Zend_Application_Module_Autoloader(
            array(
              'namespace' => '',
              'basePath' => APPLICATION_PATH,
              'resourceTypes' => array(
                'form' => array(
                  'path' => 'forms',
                  'namespace' => 'Form',
                ),
                'model' => array(
                  'path' => 'models',
                  'namespace' => 'Model',
                ),
              )
            )
    );

    return $autoloader;
  }



  protected function _initLayoutHelper()
  {
    $this->bootstrap('frontController');

    $layout = Zend_Controller_Action_HelperBroker::addHelper(new Eat_Controller_Action_Helper_LayoutLoader());

  }

  protected function _initApplication()
  {

    $config = new Zend_Config_Ini(APPLICATION_PATH . "/configs/application.ini", APPLICATION_ENV);
    Zend_Registry::set("config", $config);


    $locale = new Zend_Locale();
    Zend_Registry::set('Zend_Locale', $locale);

    //init DB connection
    try {

        $this->bootstrap('multidb');
        $multiDb = $this->getPluginResource('multidb');

        $db = $multiDb->getDb('default');
        $db->setFetchMode(Zend_Db::FETCH_OBJ);
        $db->getConnection();
        $db->getProfiler()->setEnabled(true);

        Zend_Registry::set('db', $db);

         //Just making everything UTF8. This is a hack, need to find the proper Zend way
        $db     = Zend_Registry::get('db');
        $db->query('SET NAMES "utf8"')->execute();


    } catch (Zend_Db_Adapter_Exception $e) {

        die("Error connecting to database: " . $e->getMessage());

    }


  }

  public function _initRoutes()
  {
    /*
    $router = Zend_Controller_Front::getInstance()->getRouter();
    $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini', APPLICATION_ENV);
    $router->addConfig($config, 'resources');


    $routes['featured'] = new Zend_Controller_Router_Route(
            'featured/:id',
            array('controller' => 'index', 'action' => 'featured', 'id' => null)
    );

    Zend_Controller_Front::getInstance()->getRouter()->addRoutes($routes);
    */
  }


    protected function _initLanguages()
    {


    }


    //Initilaize zend ACL
    public function _initAcl()
    {
        //Omit the process in CLI mode
        if (php_sapi_name() != 'cli')
        {
            $helper = new Eat_Controller_Action_Helper_AclDefault();
            $helper->setRoles();
            $helper->setResources();
            $helper->setPrivilages();
            $helper->setAcl();

            //Register the ACL plugin - Then it will be called automatically,whenever an acion is called
            $this->bootstrap('frontController');
            $frontController = Zend_Controller_Front::getInstance();
       // $frontController->registerPlugin(new Eat_Plugin_Acl());


        }
    }

    //Initialize error controller
    public function _initErrorSwitcher()
    {
        $this->bootstrap('frontController');
        $frontController = Zend_Controller_Front::getInstance();
        $frontController->registerPlugin(new Eat_Plugin_ErrorControllerSwitcher());
    }

    protected function _initZFDebug()
    {
        //  Enabling this method seems to break autocomplete. Use only when needed
        $autoloader = Zend_Loader_Autoloader::getInstance ();
        $autoloader->registerNamespace ( 'ZFDebug' );

        $db = Zend_Registry::get ( 'db' );

        $cache = Zend_Cache::factory ( 'Core', 'File' );

        //Zend_Controller_Front::getInstance()->getBaseUrl();
        //APPLICATION_PATH
        $options = array ('plugins' => array ('Variables', 'Database' => array ('adapter' => $db ), 'File' => array ('basePath' => Zend_Controller_Front::getInstance ()->getBaseUrl () ), 'Memory', 'Time', 'Registry', 'Cache' => array ('backend' => $cache->getBackend () ), 'Exception' ) );

        $debug = new ZFDebug_Controller_Plugin_Debug ( $options );

        $this->bootstrap ( 'frontController' );
        $frontController = $this->getResource ( 'frontController' );
        //$frontController->registerPlugin ( $debug );


    }






}

your application & library folder should be located outside of public_html: 您的应用程序和库文件夹应位于public_html之外:

this code looks for "application" folder in parent("/../") folder (relative to index.php): 此代码在parent(“ /../”)文件夹(相对于index.php)中查找“ application”文件夹:

defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

This code adds "/../library" to include path: 此代码添加“ /../library”以包含路径:

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

So either move application & library folders outside of public_html, or remove /.. from the APPLICATOIN_PATH define (but this is undesirable as it will make your app less secure) 因此,可以将应用程序和库文件夹移到public_html之外,或者从APPLICATOIN_PATH定义中删除/ ..(但这是不希望的,因为这会使您的应用程序的安全性降低)

UPD. UPD。 if you still get the error, make sure you have this file along with other Zend files: 如果仍然出现错误,请确保具有此文件以及其他Zend文件:

library/Zend/Loader/Autoloader.php 库/Zend/Loader/Autoloader.php

If not, please download latest version of Zend Framework: 如果没有,请下载最新版本的Zend Framework:

ZF1: http://downloads.zend.com/framework/1.12.10/ZendFramework-1.12.10.tar.gz ZF1: http//downloads.z​​end.com/framework/1.12.10/ZendFramework-1.12.10.tar.gz

ZF2: http://downloads.zend.com/framework/2.3.4/ZendFramework-2.3.4.tgz ZF2: http//downloads.z​​end.com/framework/2.3.4/ZendFramework-2.3.4.tgz

You can either save it to "library" folder or unarchive it to /usr/lib64/php (so it's saved as /usr/lib64/php/Zend/), this way you won't need to have this folder for each project 您可以将其保存到“库”文件夹,也可以将其取消存档到/ usr / lib64 / php(因此将其保存为/ usr / lib64 / php / Zend /),这样,您无需为每个项目都拥有此文件夹

UPD2 search for UPD2搜索

getResource('multidb')

in your code (application folder), then try to add 在您的代码(应用程序文件夹)中,然后尝试添加

$this->bootstrap('multidb');

above that.. 在那之上..

My guess is that either your Zend Framework version is different from used in original software, or your directory structure is invalid, could you try to move library&application folders outside of public_html? 我的猜测是您的Zend Framework版本不同于原始软件中使用的版本,或者您的目录结构无效,您可以尝试将库和应用程序文件夹移到public_html之外吗?

UPD3 you can also drop me an email (mstrokin at gmail.com) and I'll try to fix that for you, I love debugging :) UPD3你也可以给我发电子邮件(在gmail.com mstrokin),我会尝试修复,对你,我爱调试:)

UPD4 try to change "getPluginResource" to "getResource" UPD4尝试将“ getPluginResource”更改为“ getResource”

A possible issue would be permissions for the "library" directory. 可能的问题是“库”目录的权限。 And it affects Linux users in most cases. 在大多数情况下,它会影响Linux用户。

If you are Linux user you may need to change them 如果您是Linux用户,则可能需要更改它们

sudo chmod 755 -R path_to_project/library

If you still experience that error then you should play around with either php.ini settings or the "library" folder location. 如果仍然遇到该错误,则应该使用php.ini设置或“ library”文件夹位置进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 require_once(Zend / Application.php):无法在其他计算机上打开流工作 - require_once(Zend/Application.php): failed to open stream- working on other computers Zend-无法加载Zend / Application.php(无法打开流)? - Zend - Couldnt load Zend/Application.php (failed to open stream)? PHP,Zend,require_once:“无法打开流”和“需要打开失败[…]” - PHP, Zend, require_once: “failed to open stream” and “Failed opening required […]” 得到“ require_once(Zend / Loader / Autoloader.php):打开流失败:没有这样的文件或目录” - Getting “require_once(Zend/Loader/Autoloader.php): failed to open stream: No such file or directory” Zend 框架错误:无法打开需要“Zend/Application.php” - Zend Framework Error: Failed opening required 'Zend/Application.php' Zend框架中Application.php的位置 - Location of Application.php in Zend Framework require_once缺少学说的zend框架 - require_once missing doctrine zend framework PHP require_once 无法打开流权限被拒绝 - PHP require_once failed to open stream permission denied PHP警告:require_once:无法打开流:在目录中没有这样的文件或目录 - PHP Warning: require_once: failed to open stream: No such file or directory in PHP 警告:require_once 无法打开流:中没有这样的文件或目录 - PHP Warning: require_once failed to open stream: No such file or directory in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM