I have a problem when adding a library in zend framework 1.12 which is I have to put this script before each route to take the library:
require_once Zend_Registry::get('lib_dir')."....
there a way to make it easier?, since many files to modify. Greetings and thanks in advance!
My structure is as follows:
>Auth
>application
>configs
>controllers
>forms
>models
>views
>Bootstrap.php
>docs
>library
>lib
>Google
>Auth
>Cache
>Client.php
......
In my 'UserController' I have the following:
require_once(__DIR__.'/lib/Google/Client.php');
Zend_Loader_Autoloader::getInstance();
$client_id = '1255128545685269859856666.apps.googleusercontent.com';
$client_secret = 'sadFGHDMsdfgh-42552';
$redirect_uri = 'http://localhost/auth/public/user/login';
$client = new Google_Client();
$client->setApplicationName("Procesos");
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"); /* Datos Gmail y Google+ */
In my 'Bootstrap.php' I have the following:
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAutoload() {
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('lib_');
}
}
Application.ini
includePaths.library = APPLICATION_PATH "/../library"
autoloaderNamespaces[] = "lib_"
Depending on where you are in your project, I would recommend you to migrate your libraries dependencies to composer:
If you are able to do that, you will not have to struggle adding any other library, as most of them are available on Composer, and they are automatically loaded by Composer autoloader.
A bit more dirty, you can still use composer to autoload Google Api, by just adding your library with composer and then including your composer autoloader in your index.php (or whatever your front controller file is called).
There are other solutions, but they all require including many files.