I’ve registered a Doctrine 2 class loader via Yii::registerAutoloader for the Doctrine 2 library and my own library situated in a new directory outside of the protected directory called ‘vendor’.
protected
public
- index.php
- etc.
vendor
- Doctrine
- Application (my library)
yii
I have created a class inside my application that extends CHttpRequest so that I can write to a MongoDB store. It is namespaced Application\Session\MongoDbSession. I have also extends CWebUser to Application\User. In my main.php config, I have made the following settings;
Yii::setPathOfAlias('vendor', VENDOR_DIR);
Yii::setPathOfAlias('Application', VENDOR_DIR . '/Application');
//..
'session' => array(
'class' => 'Application\Session\MongoDbSession',
'document' => 'Application\Documents\Session',
'dm' => 'default',
)
//..
'user'=>array(
'class' => 'Application\User',
'allowAutoLogin' => true,
),
Now with all that configured, I am instantiating a new object inside of the MongoDbSession::writeSession;
public function writeSession($id,$data)
{
var_dump(new \Application\Documents\Session);
}
From a controller, I am testing itby calling Yii::app()->session->writeSession(‘foo’, ‘bar’). The new object is instantiated correctly. If however, I call Yii::app()->user->setState(‘foo’, ‘bar’), a PHP fatal error is thrown stating it cannot load the class - this error is not caught by Yii.
Am I setting up the autoloader correctly? Is there something missing in the config?