autoload

PHP trying to use autoload function to find PDO class

China☆狼群 提交于 2019-12-05 08:16:32
This has been bugging me for some time now and I can't seem to make sense of it. My phpinfo reports that PDO is installed and I can connect to my database on my index.php file. But when I try to open a PDO connection on a namespaced class, php is trying to use my autoload function to find PDO.php which won't work. My class is as follows: abstract class { protected $DB; public function __construct() { try { $this->DB = new PDO("mysql:host=$host;port=$port;dbname=$dbname", $user, $pass); } catch(PDOException $e) { echo $e->getMessage(); } } } And the error is Warning: require_once((...)/Model

autoload and namespaces

我们两清 提交于 2019-12-05 06:20:44
问题 I've been working with PHP for a long time, but am now starting to experiment with newer language features such as namespaces. I have a question regarding autoloading that I haven't been able to find an adequate answer to in my web searching. Suppose I have classes in different namespaces: namespace foo\bar\baz; class Quux { } namespace fred\barney\wilma; class Betty { } Then suppose I had an autoloader that assumes that there's a 1:1 mapping between namespaces and directory structures:

Yii import or include

守給你的承諾、 提交于 2019-12-05 03:11:06
I encountered a problem about importing php files. Why this works: include( Yii::getPathOfAlias( 'ext.payu.payU').'.php' ); but that don't: Yii::import( 'ext.payu.payU'); ? file payU.php: include_once( dirname(__FILE__) . "/sdk/openpayu.php"); //this is a valid path class payU{ } Try to do Yii::import('ext.payu.payU', true) because default one-parameter Yii::import() function call means: hey, just add this path to the known aliases list and do not require() it now and you have to do new payU() for this to work. Import works the follow way: Open Directory and Load the Class within the php file

Are there performance downsides while using autoloading classes in PHP?

百般思念 提交于 2019-12-05 01:53:31
Currently I load in all my classes by including a "all.inc.php" file on every page of my site, this file then goes on to include all the config, classes, functions, etc. that I will use on the whole site. My issue with this is that often I use classes that only pertain to certain pages/sections of a website, so often I am including a bunch of classes at the start of the page which will not be used. Obviously autoloading the classes would fix this issue, so my question is, would autoloading the classes give me a performace downside as the server then has to check if a file exists? And if there

spl_autoload_register()函数的作用

冷暖自知 提交于 2019-12-05 01:38:11
复习__autoload的时候,看到了spl_autoload_register()这个函数。但是一下子没有弄明白,通过查资料我算是弄明白了。 1.__autoload() —— 自动加载函数 我把很多个类文件以 类名.class.php的形式存放在class目录中,在class的同级目录中建立一个index.php。进入class目录里面分别建立class1.class.php、class2.class.php、class3.class.php文件,分别为里面的文件添加一下代码 <?php //class1.class.php中 class class1{ public function __construct(){ echo "class1"; } } ?> <?php //class2.class.php中 class class2{ public function __construct(){ echo "class2"; } } ?> <?php //class3.class.php中 class class3{ public function __construct(){ echo "class3"; } } ?> index.php文件中写入 <?php function __autoload($classname){ $filename = "./class/".

sqlalchemy autoloaded orm persistence

本小妞迷上赌 提交于 2019-12-05 00:41:30
问题 We are using sqlalchemy's autoload feature to do column mapping to prevent hardcoding in our code. class users(Base): __tablename__ = 'users' __table_args__ = { 'autoload': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8' } Is there a way to serialize or cache autoloaded metadata/orms so we don't have to go through the autoload process every time we need to reference our orm classes from other scripts/functions? I have looked at beaker caching and pickle but haven't found a clear

Laravel 4: loading an old library: how?

最后都变了- 提交于 2019-12-04 22:16:28
问题 I have an old library (phpquery) that I'd like to include in my project. I've put it inside vendor, but it doesn't work, as it's not PSR-0 compliant. I don't want it to load for every request, so I didn't put the require inside bootstrap autoload.php. I don't even know, how I can get the root of the app. Running path() gives me a URL, not what I'm after. So how can I do that? 回答1: You can create a libraries directory just like in laravel 3 and include it in your class loader. You can do this

Unable to AutoLoad Class using Composer

风流意气都作罢 提交于 2019-12-04 20:34:15
I have a project structure that looks like: app/ app/models/ app/controllers/ app/views/ public/ vendor/ composer.json Inside of app/controllers/IndexController.php, I have: require '../vendor/autoload.php'; use MyApp\Models\Test; class IndexController { public function __construct() { $t = new Test(); // can't be found } } Here's my composer.json: { "require": { "aws/aws-sdk-php": "*", }, "autoload": { "psr-0": { "MyApp": "app/" } } } After updating composer.json, I run composer.phar update to update the generated autoload files. FYI - I'm not using any type of MVC framework. This is just a

Multiple Composer Installs with (Independent) Modular Projects

社会主义新天地 提交于 2019-12-04 19:27:27
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 multiple composer installs would probably install a lot of the same dependencies. And I can't have them all

Conflict between Codeigniter AUtoload and Flourish Autoload functions

梦想的初衷 提交于 2019-12-04 19:22:12
I am developing a web application, using the Codeigniter ( http://codeigniter.com/ ) framework plus the Flourish library ( unframework ) ( http://flourishlib.com/ ). I simply dropped the flourish folder into my application, then I created a flourish initialization and config files as instructed (these create the Flourish autoload). This is my folder structure: ---auxcode\ --------init.php --------config.php --------flourish\ ---system\ ---application\ ---public_html\ The init file ONLY includes the config file, and the config file contents shown below: function __autoload($class_name){ { //