Yii Framework Forum: How to reuse models - Yii Framework Forum

Jump to content

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

How to reuse models Make reusable models Rate Topic: -----

#1 User is offline   Thureos 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 13-February 12

Posted 18 April 2012 - 12:40 PM

Hi everyone,

We're gonna migrate all our apps to Yii. My colleagues and me have no experience with this framework, but all of us think is the right for us to accomplish this task.

We have a doubt:

How can we make reusable models so all of our apps can use common tables like cities or states without making the same model in every new app we develop.

Thanks in advanced.

Sorry for my english.
0

#2 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 778
  • Joined: 02-July 10
  • Location:Central Poland

Posted 18 April 2012 - 02:43 PM

you can keep them in separate directory, then create alias for this directory and add it to default search like this:

(config main.php)
Yii::setPathOfAlias( 'common', '/opt/common' ); 

return array(
	'basePath'=>dirname( dirname( __FILE__ ) ),
	'name'=>'Yii Application',
	'import'=>array(
		'application.models.*',
		'application.components.*',
		'common.*',
		'common.subdirectory.*',
	),
...


and that's all. you can reference models simply by using them:

$model = new CommonModel();
red
1

#3 User is offline   Thureos 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 13-February 12

Posted 18 April 2012 - 04:11 PM

View Postredguy, on 18 April 2012 - 02:43 PM, said:

you can keep them in separate directory, then create alias for this directory and add it to default search like this:

(config main.php)
Yii::setPathOfAlias( 'common', '/opt/common' ); 

return array(
	'basePath'=>dirname( dirname( __FILE__ ) ),
	'name'=>'Yii Application',
	'import'=>array(
		'application.models.*',
		'application.components.*',
		'common.*',
		'common.subdirectory.*',
	),
...


and that's all. you can reference models simply by using them:

$model = new CommonModel();


Red Guy, you're the man!!

Thanks!
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