开发者

Accessing other classes defined in a Model Class file in Zend Framework

I have a model class "Application_Model_Person" located in application/models/Person.php that also defines other classes, like Gender and Age:

class Age
{
   ...
};

class Gender
{
   ...
};

class Application_Model_Person
{
   ...
}

My problem is that I want to access Age and Gender in a controller, but I don't know how. Calling new Application_Model_Age doesn't work because Age.php doesn't exist. I want these classes to stay in Application_M开发者_如何学Goodel_Person because they are strongly related.

Any ideas?


Well, either create Application_Model_Age and Application_Model_Gender include the File via

require(APPLICATION_PATH . '/models/Person.php');
$age = new Age();
$gender = new Gender();

I would suggest the first way though. Several Classes in one named File ... might be a personal opinion, but i think that's not the most straightforward thing to do. Even though i understand the relation between the three Classes ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜