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

Method 'GetLast' not found in Model

Im new to phalconphp and know the basics about php, im trying to learn phalconphp because it's awesome. I read through some documentation and followed a few tutorials. I made myself a skeleton with use of the tutorial but now something is driving me crazy.

I tried to use model::getLast(); but it doesn't work. Whenever I use Model::findFirst(); it works correctly but when I try to use model::getLast(); the word "getLast" gets marked and it says the following: "Method 'GetLast' not found in Model" "Referenced method is not found in subject class". (using phpstorm)

I have downloaded the latest phalcon devtools and installed it as an external library. Maybe im missing something but I find it odd that findfirst is working and getlast isn't. I Hope I gave enough information about my problem since im pretty new to this.

edited Oct '16

There is just no such method. What exactly getLast means ? findFirst is just for selecting ONE item. It's just results Model class, find is for returning resultset - object way of storing array in phalcon. What is supposed getLast to do ?



1.2k

Sorry stupid mistake I didnt mean model::getLast(); but I meant the following:

        $tekstID = teksten::find();
        $tekstID->getLast();

getLast is to get the last record in the resultset as a row

whenever I try to use the find/getlast, getLast() gets marked and it tells me:

"Method 'getLast' not found in Phalcon\Mvc\Resultsetinterface" "Referenced method is not found in subject class"

I wanted to get the last inserted ID from a table, I already solved it with the following code:

    $tekstID = teksten::find(array('order'=>'id DESC', 'limit'=>1));

    foreach ($tekstID as $value) {
        $this->view->tekstID = $value->teksten;
    }

but if anyone knows why getLast doesnt work, I think I oversee something or maybe forgot to use something.

        $tekstID = teksten::find();
        $tekstID->getLast();

This is very bad syntax ! It will select ALL RECORDS from teksten table. Your second way is correct. But use just findfirst like this:

$tekstID = teksten::findFirst(['order'=>'id DESC']);
$this->view->tekstID = $value->teksten;

Also read docs :) Don't know though why getLast is not working, what phalcon version yo use ?