Trouble setting up php Zend include path - php

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:
include("ZendFramework-1.10.3-minimal/library/Zend/Service/Amazon.php");
However inside of Amazon.php is the line
require_once 'Zend/Rest/Client.php';
...and then Client.php has more dependencies set up like that, and so on.
How can I set up my include path so that Amazon.php and Client.php (and so on) can correctly reference the location of the Zend Framework?
Thanks

You will have to set your include path using set_include_path() in your Bootstrap file if you are using any. (need to check the ZF layout for details if you are using the ZF).
The Loading of the classes will be handled by the Zend Loader when you include the library/Zend/Loader.php file and calling the function that will enable the automatic loading of classes that reside in your library/Zend folder.
When you set the include path to your library, include the library/Zend/Loader.php and call Zend_Loader::registerAutoLoad() I believe will be able to work without problems.
Short example in a file called bootstrap.php
set_include_path('ZendFramework-1.10.3-minimal/library/'.get_include_path());
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();

Related

How to include autoload in module in drupal 7

I want to use aws-sdk for php client in a custom module of drupal. I need to include vendor/autoload.php in module. But when I include it, it gives me error. I have tried to include many ways but did not get success. I added it as:
require __DIR__.'/vendor/autoload.php'; at the top of the file of .module file. Then the website gets crashed. Please could you tell how I should use require __DIR__.'/vendor/autoload.php';
I'm not sure about how drupal handles autoloading of external php modules. But with the experience of working with frameworks like laravel, cakephp and with composer, I'm sure that the target file which is index.php which routes to a number of different controllers in root directory already includes vendor/autoload.php. If it does not include, add the require statement which points to autoload.php relative to index.php or absolute path. Then using namespaces in php, you can use external php modules which are then autoloaded.
require __DIR__.'/vendor/autoload.php'; // Incase vendor directory is in same level as index.php file
require dirname(__DIR__).'/vendor/autoload.php'; // Incase vendor directory is in parent level as index.php file
It's hard to know without the actual error message. If you're getting a white screen you need to enable display of full errors (admin/config/development/logging) so you can see what's actually going on and if the classes you're relying on aren't being included in the first place, or there's some sort of conflict (remember also to clear the cache after changing anything significant).
Here's how I've gone about adding 3rd party packages in custom D7 modules:
generate a composer.json file that installs it in vendor/
require vendor/autoload.php from [modulename].module
In detail:
change to module directory
run composer init
follow prompts (it'll ask "Would you like to define your dependencies interactively" - choose yes then you can search by name)
use drupal-module for type
you can use "proprietary" for license if you don't want anyone else to use your code, this the composer.json validate cleanly (composer validate)
When finished you should have a vendor directory that includes an autoload.php file and /composer directory. "Require" this from your .module file, e.g.:
require 'vendor/autoload.php';
drush cc all
You should now be able to use your code.
Note there's a Drupal module called xautoload - (in my opinion) overkill for this.
I had wondered if a simple files[] = line for the autoload.php in [modulename].info would work - it doesn't, regardless of order.

How to include files in PHP Phalcon controllers

my file structure for phalcon is something like this
--app
-----controllers
-----models
-----views
-----functions
-----libraries
where functions and libraries folder contains some third party scripts like facebook log in etc, when I include the script in my controller classes, I did
include "../functions/facebook.php"
but it gives a file not found error.
How should I include files in the controller classes?
Ideally you should be using an autoloader Phalcon provides for automatically loading classes.
For non-classes, did you try using full path?
include __DIR__ . "/../functions/facebook.php";

bootstrap.php file in CodeIgniter PHP framework?

I am new in php. I am learning Code Igniter (a PHP framework). Can anybody let me know is there any bootstrap.php file in codeIgniter ? And if yes then what it does?
I googled but no luck for bootstrap.php file for CodeIgniter, however i got the bootstrap.php file for Zend and one other framework.
Many Thanks.
application/config
From the question, I'm assuming you would like to know where this file is to add something to it.
The bootstrap file in CakePHP is for additional application settings and setup logic - the equivalent file in Codigniter is probably the application/config/config.php file.
The bootstrap file in Zend contains a class used for initializing the whole application , which by default reads a config.ini file. Depending on specifically what it is you're looking for in "bootstrap.php file in CodeIgniter" - again, the application config files are the CI equivalent of this file's logic/purpose.
The CodeIgniter bootstrap file is the CodeIgniter.php located in system/core.

how to include file in zend framework controller?

hello I am newbie in zend framework ..
I want to know how to includes files in zend framework Controller
I am using action in zend framework controller like that
public function anyAction()
{
require("../mailchimp/anyfile.php");
}
what I can do to include this files, means where is the right place to kept all this files
This is what the library directory is typically used for. You can put your own functions in there as well as any 3rd party code. Some even put the ZF library in there, but I tend to keep ZF elsewhere on the server and add it to the include_path in php.ini.
With the mailchimp files in your library folder, you can include them like this:
require_once APPLICATION_PATH . '/../library/mailchimp/MCAPI.class.php';
If you add library to your path, then you could shorten it to just:
require_once 'mailchimp/MCAPI.class.php';
You can add library to your path by adding includePaths.library = APPLICATION_PATH "/../library" to your application.ini file. Just be aware of the possible performance penalty you may take by adding additional locations to your include_path.
EDIT:
To display an image that you have stored in public/images, you would use this call from your view/layout:
<img src="<?php echo $this->baseUrl('images/file.jpg') ?>" alt="file.jpg" />
This takes care of figuring out what your base URL is in the event that your Zend Application is not in the root directory of your domain. See the BaseUrl View Helper for more info.
In Zend-Framework you must follow MVC pattern to create any page. when you want to use/call this page you write url using module, controller and action like bellow:
require($this->url(array('module'=>'default','controller'=>'mailchimp','action'=>'mailchimp')));

How to Use Zend Library without installation of Zend Framework

How to use zend library without using zend framework installation?
I am trying to use zend library(Mail and Mime) without zend framework installation, its not returning any error messages...
but for my project i'm using Mail and Mime library only, How to use Zend Library without installing zend framework ..
Thanks,
Vinoth S
Download Zend Framework and put it into a folder accessible by your PHP. Then either do
include '/path/to/folder/containing/Zend/lib/Zend/Mail.php';
include '/path/to/folder/containing/Zend/lib/Zend/Mime.php';
$mailer = new Zend_Mail;
Or - better and more conventient - setup your autoloader and/or include path so PHP can find the classes directly, without you having to include them.
Also see
the requirements appendix for a detailed list of requirements for Zend Framework.
Register the autoloader and set include path like this:
set_include_path(implode(PATH_SEPARATOR, array(
realpath('./library'),//the path
get_include_path(),
)));
require "Zend/Loader/Autoloader.php";
$autoloader = Zend_Loader_Autoloader::getInstance();
I've done it more than once to integrate zend libs in other non-zend projects.
Autoloader is not suggested for just inclusion of some libraries as it involves in worse performances (see zend reference about |end_Loader for that).
The best way (from both clear code and performances point of view) is very simple:
1) set the include path: (necessary or you'll have fatal inclusion errors):
set_include_path(implode(PATH_SEPARATOR, array(
'/',
get_include_path(),
)));
2) do a "require_once" of the library/ies you need, following the structure Zend/
e.g:
require_once "Zend/Mail.php";
//you can use now Zend_Mail* classes
note1: you don't have to place a "require_once" of all the needed classes, the main included class already do a require_once of the dependent classes.

Categories