开发者

Static constants and methods in a Zend Framework model class

开发者 https://www.devze.com 2023-03-26 17:55 出处:网络
I have a Zend Framework model class like this class UserModel extends Zend_Db_开发者_如何学运维Table_Abstract

I have a Zend Framework model class like this

class UserModel extends Zend_Db_开发者_如何学运维Table_Abstract
{
    protected $_name = 'users';
    protected $_primary = "id";

    const SEX_MALE = "male";
    const SEX_FEMALE = "female";

    const MIN_AGE = 13;

    public static function age(Zend_Date $bornDate) {

        $now = new Zend_Date(null, null, Zend_Locale::BROWSER);

        $diff = $now->sub($bornDate);

        $age = floor($diff->toValue() / 31556926);

        if ($age < 0) {

            throw new Zend_Date_Exception("invalid date");

        }

        return $age;

    }

}

It will have all the function to insert, remove or update records.

But when I try to access to the static function or to the static constant it says that it don't find the class.

How can I can make the class visible?


It all depends how you use your classes and in this case a model class. I can only assume you have a file named UserModel.php. If you have such a file and you follow a default setup than you have it in your application/models folder. If that's what you have than the problem is simple. Rename the class to Application_Model_UserModel. You will, of course, have to call the class with this new name!

If you don't have a default setup then you probably are missing an include() for the file where the class is located.

0

精彩评论

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