1

I have been working with Yii framework for a while, but know I am trying to work on my own minimalistic framework based on MVC architecture. Let's just say that I have a parent model ModelCore which extends all other models (mentioned PageModel also). It has defined method:

public function find( $condition ){
    $sql = "SELECT * FROM {$this->table()} WHERE {$condition} LIMIT 1";
    // executing query and returning the result
}

And I am stuck at the point when I want to call this method from other class (URLresolver) this way:

//...
elseif ( PageModel::find("`url` = '{$bit}'") != NULL ) {
//...

The scripts ends with fatal error: Call to undefined method URLresolver::table()

If someone can explain me how theese things work in PHP and how can I easily access a method I would be grateful.

Thanks a lot.

4

3 回答 3

1

如果使用::它指的是静态函数。如果你创建了一个对象,你必须这样做:

$obj = new PageModel( );
$obj->find(" YOUR QUERY ");

public function find( $q ){ }

如果你有一个静态方法(在这些函数中 $this 不引用对象,因为你没有创建一个new对象。

PageModel::find( $q ){}

public static function find ( $q ){ }
于 2013-08-11T14:44:39.060 回答
0

脚本以致命错误结束:调用未定义的方法URLresolver::table()

找到你在哪里调用table()似乎不存在的函数,并且......它是一种static方法吗?否则你不需要::符号,但是->

于 2013-08-11T14:44:54.767 回答
0

该错误是不言自明的:URLresolver该类没有实现(或继承)名为table. 你确定你不是想用那个名字来调用一个属性吗?

于 2013-08-11T14:45:26.313 回答