0

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_"
2
  • Could you explain your project structure? Which files are you editing with the line you quoted? Jul 14, 2014 at 19:54
  • Hello @Thomas, thanks for your quick response, you can look at my update... Jul 14, 2014 at 21:33

1 Answer 1

0

Depending on where you are in your project, I would recommend you to migrate your libraries dependencies to composer:

ZF1 with Composer

Google API with 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.