0
votes

This article explains how to use Zend in Codeigniter.http://www.beyondcoding.com/2008/02/21/using-zend-framework-with-codeigniter/

I am using XAMPP and having difficulties with path.

Q1. I am not sure what is going on here. Why do I need to set this one?

ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'libraries');

Q2. After some tweak, I changed the above code to the following.

ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . BASEPATH . 'libraries');

The output of above line is

.;C:\xampp\php\pear\;application\libraries

However I get an error such as

Message: require_once(Zend/Validate/Between.php) [function.require-once]: failed to open stream: No such file or directory

Filename: Service/Flickr.php

and

Fatal error: require_once() [function.require]: Failed opening required 'Zend/Validate/Between.php' (include_path='.;C:\xampp\php\pear\;C:\xampp\htdocs\ci_day6_working_copy\system\libraries') in C:\xampp\htdocs\ci_day6_working_copy\application\libraries\Zend\Service\Flickr.php on line 476

Original code:

<?php if (!defined('BASEPATH')) {exit('No direct script access allowed');}

/**
 * Zend Framework Loader
 *
 * Put the 'Zend' folder (unpacked from the Zend Framework package, under 'Library')
 * in CI installation's 'application/libraries' folder
 * You can put it elsewhere but remember to alter the script accordingly
 *
 * Usage:
 *   1) $this->load->library('zend', 'Zend/Package/Name');
 *   or
 *   2) $this->load->library('zend');
 *      then $this->zend->load('Zend/Package/Name');
 *
 * * the second usage is useful for autoloading the Zend Framework library
 * * Zend/Package/Name does not need the '.php' at the end
 */
class CI_Zend
{
 /**
  * Constructor
  *
  * @param string $class class name
  */
 function __construct($class = NULL)
 {
  // include path for Zend Framework
  // alter it accordingly if you have put the 'Zend' folder elsewhere
  ini_set('include_path',
  ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'libraries');

  if ($class)
  {
   require_once (string) $class . EXT;
   log_message('debug', "Zend Class $class Loaded");
  }
  else
  {
   log_message('debug', "Zend Class Initialized");
  }
 }

 /**
  * Zend Class Loader
  *
  * @param string $class class name
  */
 function load($class)
 {
  require_once (string) $class . EXT;
  log_message('debug', "Zend Class $class Loaded");
 }
}

?>
2

2 Answers

0
votes

APPPATH is relative, but you need the absolute path to your application libraries directory. You can make the following change in the index.php bootstrap file:

if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)
{
    // comment out this code:
    // $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;
    // add this code:
    $root = str_replace("\\", "/", realpath(dirname(__FILE__))).'/';
    $application_folder = $root . $application_folder;
    $system_folder = $root . $system_folder;
    unset($root);
}
0
votes

Q1: This is adding CodeIgniter's application/libraries folder to PHP's include_path. If you're not familiar with include_path, take a look at http://us3.php.net/manual/en/ini.core.php#ini.include-path. Adding a folder to the include_path means you don't have to specify the path when including a file.

Q2: Unless you've modified their definitions, APPPATH and BASEPATH are not the same thing. You're getting the error because instead of looking in application/libraries where the tutorial you linked said to put the Zend Framework files, it's looking in system/libraries.