require

how to declare all your includes in one file that will be loaded in all project in PHP

Hello i'm working on a project but, i'm sick of loading all the libraries in every single page my project directories are something like this |---x (( PHP PAGES )) |--- x1.php (( PHP FILE )) |--- x2.php (( PHP FILE )) |---y (( PHP PAGES )) |--- y1.php (( PHP FILE )) |--- y2.php (( PHP FILE )) |---includes (( LIBRARIES )) a.ph...

Include Jquery inside GreaseMonkey script under Google Chrome

As maybe some of you know google chrome has put some severe limitation on greasemonkey scripts. Chromium does not support @require, @resource, unsafeWindow, GM_registerMenuCommand, GM_setValue, or GM_getValue. And without require, I can't find a way to include jquery library in Greasemonkey script under google chrome. Does anybod...

Check if an include (or require) exists.

Hi, How do you check if an include / require_once exists before you call it, I tried putting it in an error block, but PHP didn't like that. I think file_exists() would work with some effort, however that would require the whole file path, and a relative include could not be passed into it easily. Are there any other ways? ...

is it bad practice to require php files rather than link to js and css?

I want to put snippets like these inside of a few php files and then require them in my main page, instead of using "pure" css and js files. I mean, I already do essentially this for my HTML DOM. this: <script type='text/javascript'> var foo = <?php echo $bar; ?>; </script> or this: <style type='text/css'> .foo{ background-image:url...

Php - check if an include or block of code has an error...

How would I go about checking if and include or a require has an error in it. For example, and include would try to be included, if that page has an error the page isn't included and a message is throw? Cheers. ...

PHP: Can include a file that file_exists() says doesn't exist

In my script, I set the include path (so another part of the application can include files too), check that a file exists, and include it. However, after I set the include path, file_exists() reports that the file does not exist, yet I can still include the same file. <?php $include_path = realpath('path/to/some/directory'); if(!is...

Caching functions instead of require_once in php

Hi guys, I've been using APC caching functions and it's been phenomenal. I was thinking, why not just cache all of my functions, and load them whenever I need to (kind of like frameworks actually). function Foo {echo 'bar';} $foo = Foo; apc_store('foo',$foo); And then whenever Foo is needed, I'd just use apc_fetch. Is that more effic...

How to include/require/load a file in ruby with instance variables

I would like to put a large variable definition in a separate file for the sake of getting it out of the way. I must be doing something wrong though, because my puts call isn't putting anything out. my_class.rb: class foobar def initialize require 'datafile.rb' puts @fat_data end end datafile.rb: @fat_data = [1,2,3,4,5,6...

pluralize function in ruby NOT RAILS!

Writing some ruby code (not rails) and I need to handle something like this: found 1 match found 2 matches I have rails installed so maybe I might be able to add a require clause at the top of the script, but does anyone know of a RUBY method that pluralizes strings? Is there a class I can require that can deal with this if the script...

Cleanest/One-liner way to require all files in directory in Ruby?

When creating gems, I often have a directory structure like this: |--lib |-- helpers.rb `-- helpers |-- helper_a.rb `-- helper_b.rb Inside the helpers.rb, I'm just require-ing the files in the helpers directory. But I have to do things like this: $:.push(File.dirname(__FILE__) + '/helpers') require 'helper_a'...

php require and autoload

I use __autoload to load classes, and I keep getting errors that no class is found but file get's loaded ok. Then if I change something in a file, just something like add a new line and save it, everything works fine and class is then found. But this is a great problem cause there are thousands of files in this project and I don't want ...

PHP - Read number of dirs and then require for each a specified file name

Hello, I want to make a little script but I'm rather n00b in php so please help me if you can :) What I want the script to do is: I have "index.php". I want "index.php" to read the sub-directories from a known folder, let's say "templates/" Each sub-directory will contain a file called "content.html". The index will then load the "co...

PHP include once.

Is it more efficient to use PHP's include_once or require_once instead of using c-like include with a header guard? i.e, include_once 'init.php'; VERSUS include 'init.php'; //contents of init.php if (!defined('MY_INIT_PHP')) { define('MY_INIT_PHP', true); ... } ...

Trouble setting up php Zend include path

Hello, I am trying to set up a PHP path to my Zend Framework. I am very confused on how to do this. My Zend Framework is located at the following location on my server: amazon/ZendFramework-1.10.3-minimal I am going to be creating a couple of php files in the amazon/ directory that will require the Zend Framework. My include path is: ...

using activerecord library without installing active record gem

Hi I downloaded the active record library. I dont want to install it as gem in the system. I want to use that by requiring the lib like 'require "active_record"' How to include the path of the source code of active record. So that I can make my program to execute. ...

Is it possible to conditionally require_once, set globals, or set constants?

I have a particular php class that I want to be able to upload identical copies to two different servers. Depending on the server though, the requires will be located in different places. (the constants and globals are slightly different as well) Can I conditionally set require_once, Globals, or constants at the beginning of the file? ...

How do I temporarily change the require path in Ruby ($:)?

I'm doing some trickery with a bunch of Rake tasks for a complex project, gradually refactoring away some of the complexity in chunks at a time. This has exposed the bizarre web of dependencies left behind by the previous project maintainer. What I'd like to be able to do is to add a specific path in the project to require's list of pat...

php require class call from inside method

from my understanding, require pastes code into the calling php file. what if you were requiring from inside a method...it would paste the entire code/class inside the method, blocking the next statement in the method. eg. function test() { require 'pathtosomeclasscode'; somestatement; // any code after the require is block...

Joomla Development - Allow Direct File Access AND use Joomla-intern Framework

Hi As usual you write in Joomla Development defined('_JEXEC') or die('Restricted access'); I make a plugin which needs access from Paypal/IPN, so i exclude that in that specific file. BUT I also need to use the Joomla-intern Variables to access the Database, so i tried this: require("../filewithaccesstoframework.php"); OR even...

PHP require/include only works once in script then fails

Hi everybody, this isn't a problem as such but it's bugging me and I would appreciate any help. It might be totally obvious but I can't see it. $root_path = $_SERVER['DOCUMENT_ROOT'] require($root_path .'template/header.php') require($root_path .'template/footer.php') The script will include one or the other but not both. It will ru...