Question

I'm new to zend framework and i've found a few material about my problem, but nothing works for me. I'm trying to commecto to an API through Zend so i decided to connect in the indexAction in the IndexController.php. I could paste the code but the server stops before the code i'm writing, at the third line of the script saying:

 Debug Error: /imball-reagens/application/controllers/IndexController.php line 4 -
 Class 'Zend_Controller_Action' not found

Si i downloaded the zend framework again and i placed the library folder of the download in the library folder of my project. The in the "index.php" file of my project i typed:

require_once 'Zend/Controller/Action.php';

But the class is still not avalable. And the require doesn't throw any exception.

What am I doing wrong? How do you usually start a project in zend? Don't you use IndexAction controller? Shouldn't the library be included by default in a zend project? I started the project with zend studio and my index.php says:

if (function_exists('zend_deployment_library_path') && zend_deployment_library_path('Zend Framework 1')) {
    $paths[] = zend_deployment_library_path('Zend Framework 1');
}

I'm using Zend Framework 1.12 Thanks for the help


Update:** The index.php complete file:

 <?php

 // Define path to application directory
 defined('APPLICATION_PATH')
 || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

 // Define application environment
 defined('APPLICATION_ENV')
 || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

 $paths = array(realpath(APPLICATION_PATH . '/../library'));
 if (function_exists('zend_deployment_library_path') && zend_deployment_library_path('Zend Framework 1')) {
    $paths[] = zend_deployment_library_path('Zend Framework 1');
}
  $paths[] = get_include_path();
  set_include_path(implode(PATH_SEPARATOR, $paths));

  /** Zend_Application */

  require_once 'Zend/Application.php';
  require_once 'Zend/Controller/Action.php';

  // Create application, bootstrap, and run
  $application = new Zend_Application(
      APPLICATION_ENV,
      APPLICATION_PATH . '/configs/application.ini'
);

  $application->bootstrap()
             ->run();

Complete IndexController.php:

 <?php

 class IndexController extends Zend_Controller_Action
 {

     public function init()
     {
         /* Initialize action controller here */
     }

     public function indexAction()
     {
         try {
             $uri = "http://api.box.com/2.0/folders/0/items?";

        $headers = array(
        'Authorization:  Bearer API_KEY',
        );

        $config = array(
            'adapter'   => 'Zend_Http_Client_Adapter_Curl',
            'curloptions' => array(CURLOPT_FOLLOWLOCATION => true,
                                   CURLOPT_HTTPHEADER=>$headers,
                                   CURLOPT_SSL_VERIFYPEER=> false
                                   //CURLOPT_USERPWD, "username:password"
                                  ),
        );
        $client = new Zend_Http_Client($uri, $config);
        $response = $client->request();
        $text= $response->getBody();
        $view = new Zend_View();
        $view->assign(text, $text);
    } catch (Zend_Exception $e) {
            echo "Message: " . $e->getMessage() . "\n";
            // Other code to recover from the error
    }
}


}
Was it helpful?

Solution

Not sure if your index.php code is correct. Normally you'd need to have something like this:

// define path to application directory
defined('APPLICATION_PATH')
        || define('APPLICATION_PATH', __DIR__ . '/../application');

// Define application environment
defined('APPLICATION_ENV')
        || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') 
        ? getenv('APPLICATION_ENV') : 'production'));

// set include path
set_include_path(realpath(APPLICATION_PATH . '/../library')
        . PATH_SEPARATOR . get_include_path());

require_once 'Zend/Application.php';

OTHER TIPS

use,

require_once 'Zend/Application.php';

in your index.php instead of require_once 'Zend/Controller/Action.php'; and try.

upadte

make sure you are using zf1.12 library not the zf >2..

Zf1 downland LINK

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top