MODX3: REST API Problem own Controller

Dear Community,

I try the restful api as described in docu:
https://docs.modx.com/3.x/en/extending-modx/developing-restful-api

I have modx 3.01 test installation and created a custom table “todos”.
I used ExraBuilder.

With a test snippet I get data:


<?php
$items = $modx->getCollection('todo\Model\Todos');

$output= [];
foreach($items as $item){
    $item_array = $item->toArray();
    $output[] = json_encode($item_array);
    
}

return implode("<br>", $output);

I created a Controller unter /rest/Contollers/Todos.php

<?php

class MyControllerTodos extends \MODX\Revolution\Rest\modRestController
{
    public $classKey = 'Todos';
    public $defaultSortField = 'id';
    public $defaultSortDirection = 'ASC';
}

But I got alwas no data from api: total 0

In error_log I have the following:


|ERROR|/www/reacttest/core/vendor/xpdo/xpdo/src/xPDO/xPDO.php|666|
|Could not load class: Todos from mysql.todos|

What do I have made wrong?

Thank you in advance.

Bye
Chris

Try this:

<?php
class MyControllerTodos extends \MODX\Revolution\Rest\modRestController
{
    public $classKey = 'todo\Model\Todos';
	public $classAlias = 'Todos';
    public $defaultSortField = 'id';
    public $defaultSortDirection = 'ASC';
}

yes, thats it.

Thank you so much. :pray:

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.