views:

728

answers:

4

I've put the Zend library folder into classes folder of my app and renamed all files and folders to lowercase ( using Ant Renamer ).

When I call Zend_Feed, instead of loading /classes/zend/feed.php, kohana loads Zend from my servers share\ZendFramework\library\Zend\ (Zend Server), so I get a Cannot redeclare class Zend_Uri_Http error.

ZF version; 1.10 Kohana version: the most recent files available through GitHub

Edit: Solved, look at my answer below. Just modify the original auto_load in order to do whatever you want to :)

A: 

its very important that your class name matches the file path in ko3. e.g. your feed class is inside /classes/zend/feed.php so it must be named class Zend_Feed { if you don't like this you can create this file /classes/feed.php and do this class Feed extends Zend_Feed { }

antpaw
It already is that way, zend's got a very similar autoload as kohana
Kemo
+3  A: 

Kohana autoloader expects lowercase filenames. You can register both Zend and Kohana autoloaders and it should work fine.

In bootstrap you have:

/**
 * Enable the Kohana auto-loader.
 *
 * @see  http://docs.kohanaphp.com/features/autoloading
 * @see  http://php.net/spl_autoload_register
 */
spl_autoload_register(array('Kohana', 'auto_load'));

Zend autoloader should go before or after that (I don't know if that makes a difference). Found a post how to do it: http://www.beyondcoding.com/2009/10/29/using-zend-framework-1-8-with-kohana/

Pomyk
And where exactly do I register that? I'm new to Kohana and don't really know where and how I'm supposed to define autoload for, lets say, every class name with Zend_ prefix. Bootstrap ? How ?
Kemo
tnx for all your effort, I managed to do it myself
Kemo
A: 

Found a way around all this. I've put a file called kohana.php into my classes folder and modified the original autoload a bit;

<?php defined('SYSPATH') or die('No direct script access.');

class Kohana extends Kohana_Core {

    public static function auto_load($class)
    {
        set_include_path(APPPATH . 'classes');      

        if ( strtolower( substr( $class, 0 , 4 ) ) == 'zend' ) :

            $file = str_replace( '_', '/', $class );            ## Zend Framework

        else :

            // Transform the class name into a path
            $file = str_replace('_', '/', strtolower($class));  ## Other classes

        endif;

        if ($path = Kohana::find_file('classes', $file))
        {
            // Load the class file
            require_once $path;

            // Class has been found
            return TRUE;
        }

        // Class is not in the filesystem
        return FALSE;
    }
}

Works like a charm :)

Kemo
A: 

As Pomyk says, try to use both autoloaders: http://www.php.net/manual/en/function.spl-autoload-register.php

Reneming classes is bad practice, because it's very difficult to update and feauture support

nex2hex