views:

59

answers:

2

Hello, I'm new to zend framework so maybe this question is stupid..

I've got a default hierarchy

site
|--bootstrap.php
|--application
|--models
   |-- Item.php
   |-- ModelAbstract.php
|--...

Inside Item.php there's

<?php
    //TODO: trying to remove this require...
    require_once('ModelAbstract.php');

    class CF_Model_Flower extends CF_Model_Abstract
    {
      ...

Inside 'ModelAbstract.php' there's

<?php

    class CF_Model_Abstract
    {
     ...

And my application Bootstrap.php looks like

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initAutoload()
    {
        $autoloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'CF',
            'basePath'  => dirname(__FILE__),
        ));
        return $autoloader;
    }
  ...

If I removed the 'require_once' inside Item.php I get

Fatal error: Class 'CF_Model_Abstract' not found in /Mysite/application/models/Item.php on line 6

Why ? And how can I use autoloading to live without this require_once ?

In fact, renaming 'ModelAbstract.php' to 'Abstract.php' works. Can someone explain me why ?

Thx

A: 

I'm not familiar with Zend_Application_Module_Autoloader and such. But if they work anything like earlier ZF autoloading mechanisms, the autoloader will look for class CF_Model_Abstract in:

CF/Model/Abstract.php

or maybe with this namespace/basePath configuration in:

models/Model/Abstract.php

or:

models/CF/Model/Abstract.php

but probably not in:

models/ModelAbstract.php

So in other words, the underscores represent child directories.

fireeyedboy
You gave me a serious hint, I've just renamed 'ModelAbstract.php' to 'Abstract.php' and it worked ! I just can't figure out why :-/ I thought namespaces where used to prefix classes the Zend_Application_Module_Autoloader checked from 'basePath' some default ressources, ie in 'models' directory it would search classes like "CF_Model_XXX". I thought filenames where meaningless in this case.
luxquarta
A: 

Try specifying the _ in the namespace.

 $autoloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'CF_',
            'basePath'  => dirname(__FILE__),
 ));
linead
It doesn't work :(
luxquarta