autoload

Zend Framework: Autoloading a Class Library

拥有回忆 提交于 2019-11-29 00:00:33
I've got a class library in defined here .../projectname/library/Me/Myclass.php defined as follows: <?php class Me_Myclass{ } ?> I've got the following bootstrap: <?php /** * Application bootstrap * * @uses Zend_Application_Bootstrap_Bootstrap */ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { /** * Bootstrap autoloader for application resources * * @return Zend_Application_Module_Autoloader */ protected function _initAutoload() { $autoloader = new Zend_Application_Module_Autoloader(array( 'namespace' => 'Default', 'basePath' => dirname(__FILE__), )); $autoloader-

autoload and multiple directories

依然范特西╮ 提交于 2019-11-28 21:32:37
I've just been looking at php's autoload() function. Seems a nice idea, but I'm not sure how it handles multiple directories. My current development basically has a library directory structure grouping classes into subdirectories by operation. I'm wondering I have to declare a include() for each directory ... which I really hope I don't have to do. Can you advise - thanks You might want to take a look at the PEAR Convention for class names, which is really great for autoloading. Basically, it states that : The PEAR class hierarchy is also reflected in the class name, each level of the

What is autoload in php? [duplicate]

六眼飞鱼酱① 提交于 2019-11-28 20:06:01
This question already has an answer here: What is Autoloading; How do you use spl_autoload, __autoload and spl_autoload_register? 3 answers what is autoload in PHP? This will be of help to you about usage of autoload. http://ditio.net/2008/11/13/php-autoload-best-practices/ It's a magic function that helps you include / require files using class name. function __autoload($class_name) { require_once $DOCUMENT_ROOT . “/classes/” . $class_name .“.php”; } It's deprecated at PHP 7.2.0 and spl_autoload_register is recommended for that purpose. Here is the official documentation: http://php.net

Autoload custom library in Zend Framework 2.0

无人久伴 提交于 2019-11-28 18:28:16
I need to use autoloading for my custom classes in Zend Framework 2.0 . My custom library located in /vendor/Garvey/library/Garvey . I have a simple extended AbstractTable class in /vendor/Garvey/library/Garvey/Db/Table/AbstractTable.php : <?php namespace Garvey\Db\Table; use Zend\Db\Table\AbstractTable; abstract class AbstractTable extends AbstractTable { public function getItemById($id) { } } In the index.php I have the following code: require_once 'vendor/ZendFramework/library/Zend/Loader/AutoloaderFactory.php'; Zend\Loader\AutoloaderFactory::factory(array('Zend\Loader\StandardAutoloader' =

Rails3 not reloading code in lib while in development mode

僤鯓⒐⒋嵵緔 提交于 2019-11-28 17:38:33
THE SITUATION: I have code in lib/foo/bar.rb with a simple method defined as such: module Foo class Bar def test "FooBar" end end end In my helper, FooBarHelper , I have: require `lib/foo/bar` module FooBarHelper def test_foo_bar fb = Foo::Bar.new fb.test end end In my view, I call this helper method like so: <%= test_foo_bar => In my config/environments/development.rb , I added the directory to my config.autoload_paths : config.autoload_paths += ["#{config.root}/lib/foo"] THE PROBLEM: When I change the return value of Foo::Bar.test to, for example, "MODIFIED FOOBAR" , the original return

emacs23 / elisp: how to properly autoload this library?

笑着哭i 提交于 2019-11-28 16:35:10
I am upgrading to emacs23. I find that my emacs.el loads much more slowly. It's my own fault really... I have a lot of stuff in there. So I am also trying to autoload everything possible that is currently "required" by my emacs.el. I have a module that exposes 12 entry points - interactive functions I can call. Is the correct approach to have 12 calls to autoload in order to insure that the module is loaded regardless of which function I call? Are there any problems with this approach? Will it present performance issues? If not that approach, then what? Trey Jackson What you really want is to

Composer/PSR - How to autoload functions?

孤人 提交于 2019-11-28 08:52:49
How can I autoload helper functions (outside of any class)? Can I specify in composer.json some kind of bootstrap file that should be loaded first? mpen You can autoload specific files by editing your composer.json file like this: "autoload": { "files": ["src/helpers.php"] } (thanks Kint ) After some tests, I have came to the conclusions that adding a namespace to a file that contains functions, and setting up composer to autoload this file seems to not load this function across all the files that require the autoload path. To synthesize, this will autoload your function everywhere: composer

PHP adding custom namespace using autoloader from composer

吃可爱长大的小学妹 提交于 2019-11-28 06:52:53
Here is my folder structure: Classes - CronJobs - Weather - WeatherSite.php I want to load WeatherSite class from my script. Im using composer with autoload: $loader = include(LIBRARY .'autoload.php'); $loader->add('Classes\Weather',CLASSES .'cronjobs/weather'); $weather = new Classes\Weather\WeatherSite(); Im assuming the above code is adding the namespace and the path that namespace resolves to. But when the page loads I always get this error: Fatal error: Class 'Classes\Weather\WeatherSite' not found Here is my WeatherSite.php file: namespace Classes\Weather; class WeatherSite { public

PHP Autoloading in Namespaces

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 06:34:52
I have had a slight problem with autoloading in my namespace. As shown on the PHP manual here: http://us.php.net/manual/en/language.namespaces.rules.php you should be able to autoload namespace functions with a full qualified name e.g. \glue\common\is_email(). Thing is I have a function spl_autoload_register(array($import, "load")); within the initial namespace but whenever I try and call \glue\common\is_email() from the initial namespace it will not pass that autoload function but when using new is_email() (in the context of a class) it will. I don't get it the manual says I can autoload from

Using PHP namespaces in a Zend Framework (v1) application

心已入冬 提交于 2019-11-28 06:33:16
Is it possible in the current stable version of the Zend Framework (1.11), to work with application classes using PHP namespaces? Application\Form\Abc instead of Application_Form_Abc Application\Model\Xyz instead of Application_Model_Xyz etc. Starting from v1.10, ZF supports autoloading namespaces , and it's working fine when including namespaced libraries, but I was unsuccessful when trying to do the same job with application classes. Actually there is a simple workaround suggested by Dmitry on the ZF issue tracker : class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { protected