Yii Framework Forum: Model Folder - Yii Framework Forum

Jump to content

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

Model Folder Rate Topic: -----

#1 User is offline   jbomhold3 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 06-May 10

Posted 06 May 2010 - 05:50 PM

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
0

#2 User is online   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,652
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 06 May 2010 - 06:27 PM

View Postjbomhold3, 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



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_(.*)$/


In your case the command would be
>>model application.models.database.whatevertable
or
>>model application.models.database.*

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#3 User is offline   jbomhold3 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 06-May 10

Posted 06 May 2010 - 08:06 PM

Worked perfectly ty.
0

#4 User is offline   jbomhold3 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 06-May 10

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.
0

#5 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

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.
0

#6 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 06 May 2010 - 11:56 PM

View Postjbomhold3, 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.
0

#7 User is offline   jbomhold3 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 06-May 10

Posted 07 May 2010 - 12:32 AM

much better thanks all.
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