Zendcasts Forum

A community of developers who work with the Zend Framework and other enterprise PHP technologies

You are not logged in.

#1 2010-08-10 07:46:17

Xavier
Member
Registered: 2010-08-10
Posts: 13

Autoloading problem

Hi,

I have problems with the autoloading.
I have a normal zend setup with the models folder in the application folder.

Application.ini has appnamespace = "Application"

In some way he does not load the model auto, i need to do an require_once for it ...

autoloaderNamespaces[] = "ZendX" works like a charm, but i want to use the default model folder ... any ideas what i'm doing wrong?

htaccess has :

SetEnv APPLICATION_ENV production

RewriteEngine On
#RewriteBase /
#RewriteCond %{REQUEST_URI} =""
#RewriteRule ^.*$ /public/index.php [NC,L]
#RewriteCond %{REQUEST_FILENAME} -s [OR]
#RewriteCond %{REQUEST_FILENAME} -l [OR]
#RewriteCond %{REQUEST_FILENAME} -d
#RewriteRule ^.*$ - [NC,L]
#RewriteRule ^.*$ index.php [NC,L]

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

thx,

Xavier

Offline

#2 2010-08-10 08:20:36

Jon Lebensold
Administrator
Registered: 2009-06-27
Posts: 279

Re: Autoloading problem

Hi Xavier,

you need to change "Application" in your config.ini to "" (this way, the default prefix is nothing)

Offline

#3 2010-08-10 08:28:16

Xavier
Member
Registered: 2010-08-10
Posts: 13

Re: Autoloading problem

Jon Lebensold wrote:

Hi Xavier,

you need to change "Application" in your config.ini to "" (this way, the default prefix is nothing)

Hi,

thx for your answer.

I still have the issue : Fatal error: Class 'Application_Model_Referenties' not found in ...

The models is in the standard way ...

bootstrap:

/* autoloader Application_ */
    protected function _initResourceAutoloader()
    {
     $autoloader = new Zend_Loader_Autoloader_Resource(array(
        'basePath'  => APPLICATION_PATH,
        'namespace' => 'Application_',
     ));

Last edited by Xavier (2010-08-10 08:31:23)

Offline

#4 2010-08-10 08:31:59

Jon Lebensold
Administrator
Registered: 2009-06-27
Posts: 279

Re: Autoloading problem

are you creating a [code=php] new Model_Referenties();
or new Application_Model_Referenties();
[/code]  ?

Offline

#5 2010-08-10 08:34:57

Xavier
Member
Registered: 2010-08-10
Posts: 13

Re: Autoloading problem

Jon Lebensold wrote:

are you creating a [code=php] new Model_Referenties();
or new Application_Model_Referenties();
[/code]  ?

thx for the quick answer!


    require_once(APPLICATION_PATH.'/models/referenties.php');
       
    $obj = new Application_Model_Referenties();

Deleting the application appnamespace did crash my form class.

Application -> models
                  -> forms
                  -> controller
                  -> ...

I tought the Application did tell the autoloader to default load everything in the application folder an starting with Application_

Last edited by Xavier (2010-08-10 08:37:54)

Offline

#6 2010-08-10 08:37:40

Jon Lebensold
Administrator
Registered: 2009-06-27
Posts: 279

Re: Autoloading problem

your file should be called Referenties.php. You shouldn't need to autoload it (since Zend_Autoload will do that for you).

the class inside should be (assuming your config.ini appnamespace = "")
[code=php]
class Model_Referenties
{

}
...
$obj = new Model_Referenties();
[/code]

Offline

#7 2010-08-10 08:43:10

Xavier
Member
Registered: 2010-08-10
Posts: 13

Re: Autoloading problem

Fatal error: Class 'Model_Referenties' not found in

referenties = Model_Referenties
application.inc = appnamespace ""
controller = new Model_Referenties()

I think there is something missed up somewhere, I did normal setup with Zend Tool

referenties:

class Model_Referenties
{
   
    public static function getReferenties($count = false){

        if($count){
            $sql = "SELECT * FROM referenties ORDER BY id DESC LIMIT 0,$count";
        }else{
            $sql = "SELECT * FROM referenties ORDER BY id DESC";
        }
        $db = Zend_Registry::get("db");
        return $db->fetchAll($sql);
       
    }
   
}

IndexController

class IndexController extends Zend_Controller_Action
{

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

    public function indexAction()
    {
        // action body
       
        $layout = $this->_helper->layout();
        $layout->setLayout('layout');
        /* standaard encoding, meta ... */
       
        $this->view->headTitle('Billonline');
       
        // Deze zou normaal niet geplaatst moeten worden
        //require_once(APPLICATION_PATH.'/models/referenties.php');
       
        $obj = new Model_Referenties();
        $referenties = $obj->getReferenties(2);
        $this->view->referenties = $referenties;
        $this->view->page = "home";
   
    }
   


}

application.ini

appnamespace = ""

removing the Application did crash my form class

Offline

#8 2010-08-10 09:15:37

Jon Lebensold
Administrator
Registered: 2009-06-27
Posts: 279

Re: Autoloading problem

what's the name of the php file? make sure it's "Referenties.php" (case sensitive)

Offline

#9 2010-08-10 09:23:39

Xavier
Member
Registered: 2010-08-10
Posts: 13

Re: Autoloading problem

Jon Lebensold wrote:

what's the name of the php file? make sure it's "Referenties.php" (case sensitive)

ouch ... stupid of me! thx!

Offline

Board footer

Powered by FluxBB