Yii Framework Forum: Autoload And Paths - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Autoload And Paths Rate Topic: -----

#1 User is offline   Edgar Kuskov 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 07-December 12
  • Location:Konstanz, Germany

Posted 30 January 2013 - 07:06 AM

Hellow every1,

i am a bit confused about the preload 'import' parameters in 'main.php' config file. I have just change the import to:
// autoloading model and component classes
	'import'=>array(
		'application.models.*',
		'application.modules.*',
		'application.components.*',
		'application.extensions.*',
	),


Now i have created a new folder in extension 'validators' and created a 'uniqueValidator.php' inside of validators. In the model i am adding the validator like:
array('year', 'CompositeUniqueKeyValidator', 'keyColumns' => 'year, user_id'),

and yii cant find this validator.

Now i set the alias path:
Yii::setPathOfAlias('validators', dirname(__FILE__).'/../extensions/validators');

and now i can use the model like that:
array('year', 'validators.CompositeUniqueKeyValidator', 'keyColumns' => 'year, user_id'),

What is then preloder? And why it doesnt load all the files from extensions?

Regards,

Edgar
"Don't start what you can't finish"
0

#2 User is offline   redguy 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 577
  • Joined: 02-July 10
  • Location:Central Poland

Posted 30 January 2013 - 08:05 AM

it does. but only from "extensions" directory, not subdirectories. If you want to automatically load classes from "validators" subdirectory you must add:
        'import'=>array(
                'application.models.*',
                'application.modules.*',
                'application.components.*',
                'application.extensions.*',
                'application.extensions.validators.*',
        ),

otherwise you could just type:
                'application.*',

and everything would be loaded automatically...
red
0

#3 User is offline   Edgar Kuskov 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 07-December 12
  • Location:Konstanz, Germany

Posted 31 January 2013 - 04:59 AM

View Postredguy, on 30 January 2013 - 08:05 AM, said:

it does. but only from "extensions" directory, not subdirectories. If you want to automatically load classes from "validators" subdirectory you must add:
        'import'=>array(
                'application.models.*',
                'application.modules.*',
                'application.components.*',
                'application.extensions.*',
                'application.extensions.validators.*',
        ),

otherwise you could just type:
                'application.*',

and everything would be loaded automatically...


Ok so in Yii case the " * " symbol doesnt mean that the files will be loaded recursive. But why then "application.*" loads all the files?
"Don't start what you can't finish"
0

#4 User is offline   redguy 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 577
  • Joined: 02-July 10
  • Location:Central Poland

Posted 31 January 2013 - 05:22 AM

View PostEdgar Kuskov, on 31 January 2013 - 04:59 AM, said:

But why then "application.*" loads all the files?

it does not. I just pointed that IF it worked then you would not have to specify any other paths like application.model.*, application.extensions.*, etc.

"*" in any case means only "all files from this directory" without recursion.
red
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users