We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Call getSource from static function

I try define function findByRawSql as below

public static function findByRawSql($conditions, $params = null)
    {
        // instance class name 
        $instance_class_name = $this->getSource();

        // A raw SQL statement
        $sql = "SELECT * FROM $instance_class_name WHERE $conditions";

        // Base model
        $model = new $instance_class_name();

        // Execute the query
        return new Resultset(null, $model, $model->getReadConnection()->query($sql, $params));

    }

But, $this->getSource() is error in static function



8.7k
edited Sep '15

You can't call an instance method from a static context--you need an instance first.

Try this inside your static method:

$s = new self();
echo $s->getSource();

Tks for reply!