1
votes

I'm currently getting to know Propel, but I'm having a hard time getting this to work.
To give a bit of background I want to get the last row of my table 'Message' using Propel. To archieve this I want to use the class 'Criteria'.
My problem is that PHP cannot find the class Criteria when I the programm is executed. I know I have to import the class somehow but I don't know where it is located. Here's my Code:

<?php
    session_start();
    // setup the autoloading
    require_once '/home/smalburg/propel/vendor/autoload.php';
    // setup Propel
    require_once '/home/smalburg/propel/generated-conf/config.php';


    //Get id from last row in table 
    $row = MessageQuery::create()->
    orderById(Criteria::DESC)->
    limit(1)->
    find();
?>

I have installed Propel using composer.
Here's the error message to whom it may concern (don't mind Line 17 i have shortend the code):

Fatal error: Uncaught Error: Class 'Criteria' not found in /var/www/html/propel/nachrichten_schicken.php:17 Stack trace: #0 {main} thrown in /var/www/html/propel/nachrichten_schicken.php on line 17

Please help me I refuse to go to bed before this is fixed.

Update:
I did go to bed.
First of all, PetrHejda's solution worked, but I also found an alternative way to solve my specific problem:
Instead of using orderById(\Propel\Runtime\ActiveQuery\Criteria::DESC)-> (like in Petr's solution) one can just say orderById('desc')->, which also worked fine. Thanks for the help!

1
I doubt that Criteria would be in the root namespace in that case. So you're missing a use statement, or you need to add the fully-qualified namespace to the Criteria class name. Which propel version are you using?Jonnix

1 Answers

1
votes

Propel's class Criteria is in the namespace \Propel\Runtime\ActiveQuery.

Either prepend the namespace to the class name

orderById(\Propel\Runtime\ActiveQuery\Criteria::DESC)

or import it

use Propel\Runtime\ActiveQuery\Criteria;

orderById(Criteria::DESC)