If this has been asked before i'm sorry I looked could not find it.
I'm using yiic to to generate my models for my database tables. What I would like to have it do is send the models it makes to models/database/whatevertable.php just for neatness can this be done?
Thanks,
John
Page 1 of 1
Model Folder
#2
Posted 06 May 2010 - 06:27 PM
jbomhold3, on 06 May 2010 - 05:50 PM, said:
If this has been asked before i'm sorry I looked could not find it.
I'm using yiic to to generate my models for my database tables. What I would like to have it do is send the models it makes to models/database/whatevertable.php just for neatness can this be done?
Thanks,
John
I'm using yiic to to generate my models for my database tables. What I would like to have it do is send the models it makes to models/database/whatevertable.php just for neatness can this be done?
Thanks,
John
Quote
>> help model
USAGE
model <class-name> [table-name]
DESCRIPTION
This command generates a model class with the specified class name.
PARAMETERS
* class-name: required, model class name. By default, the generated
model class file will be placed under the directory aliased as
'application.models'. To override this default, specify the class
name in terms of a path alias, e.g., 'application.somewhere.ClassName'.
If the model class belongs to a module, it should be specified
as 'ModuleID.models.ClassName'.
If the class name ends with '*', then a model class will be generated
for EVERY table in the database.
If the class name contains a regular expression deliminated by slashes,
then a model class will be generated for those tables whose name
matches the regular expression. If the regular expression contains
sub-patterns, the first sub-pattern will be used to generate the model
class name.
* table-name: optional, the associated database table name. If not given,
it is assumed to be the model class name.
Note, when the class name ends with '*', this parameter will be
ignored.
EXAMPLES
* Generates the Post model:
model Post
* Generates the Post model which is associated with table 'posts':
model Post posts
* Generates the Post model which should belong to module 'admin':
model admin.models.Post
* Generates a model class for every table in the current database:
model *
* Same as above, but the model class files should be generated
under 'protected/models2':
model application.models2.*
* Generates a model class for every table whose name is prefixed
with 'tbl_' in the current database. The model class will not
contain the table prefix.
model /^tbl_(.*)$/
* Same as above, but the model class files should be generated
under 'protected/models2':
model application.models2./^tbl_(.*)$/
USAGE
model <class-name> [table-name]
DESCRIPTION
This command generates a model class with the specified class name.
PARAMETERS
* class-name: required, model class name. By default, the generated
model class file will be placed under the directory aliased as
'application.models'. To override this default, specify the class
name in terms of a path alias, e.g., 'application.somewhere.ClassName'.
If the model class belongs to a module, it should be specified
as 'ModuleID.models.ClassName'.
If the class name ends with '*', then a model class will be generated
for EVERY table in the database.
If the class name contains a regular expression deliminated by slashes,
then a model class will be generated for those tables whose name
matches the regular expression. If the regular expression contains
sub-patterns, the first sub-pattern will be used to generate the model
class name.
* table-name: optional, the associated database table name. If not given,
it is assumed to be the model class name.
Note, when the class name ends with '*', this parameter will be
ignored.
EXAMPLES
* Generates the Post model:
model Post
* Generates the Post model which is associated with table 'posts':
model Post posts
* Generates the Post model which should belong to module 'admin':
model admin.models.Post
* Generates a model class for every table in the current database:
model *
* Same as above, but the model class files should be generated
under 'protected/models2':
model application.models2.*
* Generates a model class for every table whose name is prefixed
with 'tbl_' in the current database. The model class will not
contain the table prefix.
model /^tbl_(.*)$/
* Same as above, but the model class files should be generated
under 'protected/models2':
model application.models2./^tbl_(.*)$/
In your case the command would be
>>model application.models.database.whatevertable
or
>>model application.models.database.*
/Tommy
#4
Posted 06 May 2010 - 11:27 PM
Ok well maybe not. It loads the model in the right folder but the program can not find it. I assume I need to point it but how.
#5
Posted 06 May 2010 - 11:55 PM
Add your directory alias to the import array in the config file
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";
python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]
ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}
You say Tomato, I say Tomato.
#6
Posted 06 May 2010 - 11:56 PM
jbomhold3, on 06 May 2010 - 11:27 PM, said:
Ok well maybe not. It loads the model in the right folder but the program can not find it. I assume I need to point it but how.
Yes, it must be in the config's import section: 'application.models.database.*'.
Or anywhere else you should put Yii::import('application.models.database.*') or Yii::import('application.models.database.modelName') for a specific model.
Share this topic:
Page 1 of 1

Help















