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.

3 Answers 3

1

If you use :: it refers to a static function. If you created an object, you have to do it like:

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

public function find( $q ){ }

If you have a static method (in these functions $this does not reffer to the object, because you did not create a new object.

PageModel::find( $q ){}

public static function find ( $q ){ }
Sign up to request clarification or add additional context in comments.

1 Comment

Quite helpful. I didn't know that :: refers to a static function. I will try to handle it other way. Thank you.
0

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

Find where you are calling table() function which seems to dont exist,and... is it a static method? Otherway you dont need the :: notation, but ->

Comments

0

The error is pretty self-explanatory: the URLresolver class doesn't implement (or inherit) a method named table. Are you sure you didn't mean to call a property with that name?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.