autoload

How to add autoload-function to CodeIgniter?

情到浓时终转凉″ 提交于 2020-01-11 08:46:10
问题 I would like to be able to use OOP and create new objects in my controllers in CodeIgniter. So I need to use an autoload-function: function __autoload( $classname ) { require_once("../records/$classname.php"); } But how can I add that to CodeIgniter? 回答1: You can add your auto loader above to app/config/config.php . I've used a similar autoload function before in this location and it's worked quite neatly. function __autoload($class) { if (strpos($class, 'CI_') !== 0) { @include_once(APPPATH

Multiple Composer Installs with (Independent) Modular Projects

不羁岁月 提交于 2020-01-01 19:39:30
问题 I am trying to find the best way to use composer for a modular structure. Let's say I have this framework tree: /cms /site/addons Let's say that addons are available for developers to add their projects with their composer.json installs. Like /site/addons/MyNewFeature/composer.json So the next question is the /vendor location. Should each addon have a /vendor directory and should I autoload them all within the main framework, which I think the performance of that would be too much and

How to install the AWS SDK in Yii

谁说我不能喝 提交于 2020-01-01 11:48:28
问题 I would like to use the Amazon AWS SDK for PHP in my Yii project, however I get all kinds of include errors (such as include(CFCredentials.php): failed to open stream: No such file or directory ). I think it may be related to Yii's assumption that class names must match file names... What can we do?? 回答1: I've made that: spl_autoload_unregister(array('YiiBase', 'autoload')); require_once PATH_TO_AWS_SDK . 'sdk.class.php'; // I write down in PATH_TO_AWS_SDK.'config.inc.php' my CFCredentials

How can I autoload a custom class in Laravel 5.1?

吃可爱长大的小学妹 提交于 2020-01-01 03:06:12
问题 I've created a library folder within the app folder to add my own classes. This is the content of the file app/library/helper.php : <?php namespace Library; class MyHelper { public function v($arr) { var_dump($arr); } } I added the namespace to composer.json : and then I ran $ composer dump-autoload but it does not seem to have any effects. The files vendor/composer/autoload_psr4.php vendor/composer/autoload_classmap.php did not change. If I try to create an instance of MyHelper , Laravel

Composer autoload full example?

一个人想着一个人 提交于 2019-12-31 16:33:17
问题 I am trying to put all the peaces together I found about autoloading a class in composer but I can't make it work. Every example I see is missing some part. Basically it comes down to two files with 4 lines: index.php $loader = require 'vendor/autoload.php'; $loader->add('Vendor\\', __DIR__.'/../app/'); new Vendor_Package_Obj(); app/Vendor/Package/Obj.php class Obj {} I also tried psr-4 and all thinkable combinations of folders and names for `Vendor Package Obj? but no luck finding a working

Does the 'use' keyword trigger autoloading in PHP?

折月煮酒 提交于 2019-12-31 01:56:10
问题 In the example below, at what point does the autoloader load the class file, if at all? For example, if $boolean_test === false does the Subpackage get loaded? use Org\Group\Package\Subpackage; // autoloader triggered here? if ($boolean_test) { Subpackage::method(); // or here? } I prefer the use statement near the top of the code so I can see what packages are used in the page and for slightly better readability. But, if packages are only used based on conditionals, I may be loading unneeded

PHP class not found when using namespace

安稳与你 提交于 2019-12-29 05:32:07
问题 I am new with this namespace thing. I have 2 classes(separate files) in my base directory, say class1.php and class2.php inside a directory src/ . class1.php namespace \src\utility\Timer; class Timer{ public static function somefunction(){ } } class2.php namespace \src\utility\Verification; use Timer; class Verification{ Timer::somefunction(); } When I execute class2.php , i get the Fatal error that PHP Fatal error: Class 'Timer' not found in path/to/class2.php at line *** I read somewhere on

Do PHP opcode cache work with __autoload?

て烟熏妆下的殇ゞ 提交于 2019-12-28 04:23:06
问题 Sorry if this is basic, I am trying to learn as much as I can about OO in PHP and I am slowly learning how to use it (very limited). So I am wanting to know if __autoload() has any affect on PHP opcode cache's? 回答1: (Disclaimer : I only know APC) What an opcode cache do is : when a file is included/required, it take the full path to that file check if the opcodes corresponding to that file are already in RAM (in opcode cache) if yes, return those opcode so they are executed if no, load the

Autoload classes from different folders

孤街醉人 提交于 2019-12-27 18:25:58
问题 This is how I autoload all the classes in my controllers folder, # auto load controller classes function __autoload($class_name) { $filename = 'class_'.strtolower($class_name).'.php'; $file = AP_SITE.'controllers/'.$filename; if (file_exists($file) == false) { return false; } include ($file); } But I have classes in models folder as well and I want to autoload them too - what should I do? Should I duplicate the autoload above and just change the path to models/ (but isn't this repetitive??)?

Autoload classes from different folders

不想你离开。 提交于 2019-12-27 18:22:04
问题 This is how I autoload all the classes in my controllers folder, # auto load controller classes function __autoload($class_name) { $filename = 'class_'.strtolower($class_name).'.php'; $file = AP_SITE.'controllers/'.$filename; if (file_exists($file) == false) { return false; } include ($file); } But I have classes in models folder as well and I want to autoload them too - what should I do? Should I duplicate the autoload above and just change the path to models/ (but isn't this repetitive??)?