How to change include directory of Zend Framework

后端 未结 5 1952
后悔当初
后悔当初 2020-12-29 02:04

I get the following error messages:

Warning: include_once(Zend\\Db.php) [function.include-once]: 
failed to open stream: No such file or directory in 
C:\\Ea         


        
相关标签:
5条回答
  • 2020-12-29 02:24

    Use set_include_path(). See PHP.net documentation

    Example:

     set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/Zend');
    
    0 讨论(0)
  • 2020-12-29 02:28

    The reason the other suggestions say anything about doing that, is because it's a bad move - in other words, you're doing it wrong.

    You can create a subdirectory and name it Zendxxx, but then you have to add that to your include_path, and change it, whenever you put a newly named version up.

    I'd hazard a guess, and say that you don't have a good way to test the website (so you want to lock it to a particular version of ZF), and further, that you aren't using revision control, so you want all the previous versions of code in the site-directory to be able to go back to, if you find a problem when you change the live-running code directly on the server.

    0 讨论(0)
  • 2020-12-29 02:31

    create a directory (say 'lib'), and put your Zend directory in it. so your directory structure looks like this:

    - application
    - lib
      |- Zend
    - wwwroot
      |- index.php
    

    now you should add lib to your include path. edit your index.php file:

    $includePath = array();
    $includePath[] = '.';
    $includePath[] = './../application';
    $includePath[] = './../lib';
    $includePath[] = get_include_path();
    $includePath = implode(PATH_SEPARATOR,$includePath);
    set_include_path($includePath);
    

    now you have your lib in your include path. you can include all Zend components like this:

    include 'Zend/Loader.php';
    require_once 'Zend/Db.php';
    

    the best way is too include Zend_Loader first and then use it to load classes. do this:

    require_once 'Zend/Loader.php';
    Zend_Loader::loadClass('Zend_Db');
    

    you can also register to autoload classes. just add this line to your code after all those before:

    Zend_Loader::registerAutoLoad('Zend_Loader',true);
    

    now you do not need to include files to call classes. just instanciate your classes:

    $session = new Zend_Session_Namespace('user');

    there is no need to include 'Zend/Session/Namespace.php'.

    0 讨论(0)
  • 2020-12-29 02:44

    I usually store the framework files under a "library" folder:

    • application
    • public_html
    • library
      • Zend
      • Common
      • etc....

    and then in my bootstrap file, or front controller, I add that "library" folder to the include path:

    set_include_path(get_include_path() . PATH_SEPARATOR . '../library');
    

    See also:

    • Choosing Your Application's Directory Layout.
    • Create the Filesystem Layout.
    0 讨论(0)
  • 2020-12-29 02:44

    project without library And including library from one location
    project C:\xampp\htdocs\my\application
    library C:\xampp\Zend\library

    make changes in index.php

    // Ensure library/ is on include_path
    set_include_path(implode(PATH_SEPARATOR,  
               array(realpath(APPLICATION_PATH.'/../../../Zend/library'),get_include_path(),)));
    
    0 讨论(0)
提交回复
热议问题