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



4.0k
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!