views:

1193

answers:

3

I've got a class library in defined here .../projectname/library/Me/Myclass.php defined as follows:

<?php
class Me_Myclass{
}
?>

I've got the following bootstrap:

<?php

/**
 * Application bootstrap
 * 
 * @uses    Zend_Application_Bootstrap_Bootstrap
 */
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    /**
     * Bootstrap autoloader for application resources
     * 
     * @return Zend_Application_Module_Autoloader
     */
    protected function _initAutoload()
    {
        $autoloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'Default',
            'basePath'  => dirname(__FILE__),
        ));
        $autoloader->registerNamespace('Me_');
        return $autoloader;
    }

    /**
     * Bootstrap the view doctype
     * 
     * @return void
     */
    protected function _initDoctype()
    {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->doctype('XHTML1_STRICT');
    }

    /**
     * Bootstrap registry and store configuration information
     * 
     * @return void
     */
    protected function _initRegistry()
    {
      $config = new Zend_Config_Ini(APPLICATION_PATH . 
                                      '/configs/application.ini', APPLICATION_ENV,
                                      array('allowModifications'=>true));
      Zend_Registry::set('configuration', $config);
    }

}

In my controller I try to instantiate the class like this:

<?php
class SomeController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $classMaker=new Me_Myclass();
    }
}
?>

When I navigate directly to http:/something.com/projectname/some?id=1 I get the following error:

Fatal error: Class 'Me_Myclass' not found in /home/myuser/work/projectname/application/controllers/SomeController.php on line x

Any ideas?

Potentially Pertinent Miscellany:

The autoloader seems to work when I'm extending models with classes I've defined in other folders under application/library.

Someone suggested changing the 'Default', which I attempted but it didn't appear to fix the problem and had the added negative impact of breaking function of models using this namespace.

+1  A: 

You class needs to be name Me_Myclass:

class Me_Myclass
{
}

Move your library folder up a level so that you have the folder structure:

/
    /application
    /library
    /public

And then in your Bootstrap add the following to the _initAutoload():

    Zend_Loader_Autoloader::getInstance()->registerNamespace('Me_');
smack0007
Hello, thanks for your answer, I tried this and recieved an error below. What does that indicate?Fatal error: Uncaught exception 'Zend_Loader_Exception' with message 'Method 'registerNamespace' is not supported' in /home/myuser/work/myproject/library/Zend/Loader/Autoloader/Resource.php:128 Stack trace: http://pastie.org/799074
Please update your answer to show the changes in the code you made.
smack0007
A: 

I think @smack0007 means replace the contents of your _initAutoload method with Zend_Loader_Autoloader::getInstance()->registerNamespace('Me_'); so it looks like this:

protected function _initAutoload()
{
    Zend_Loader_Autoloader::getInstance()->registerNamespace('Me_');
}
Wannabeweb
A: 

Not sure if this is your problem, but I just spent the last day and half trying to figure out my own similar problem (first time loading it up on Linux from Windows). Turns out I was blind to my library's folder name case.

/library
    /Tlib

is not the same as (on *nix)

/library
    /tlib

Class name is typically this

class Tlib_FooMe {
 ...
}

Hope this helps someone who is similarly absentminded.

doingsitups