This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

skydiver
skydiver

I want to display a backend list but rendering custom list/array but "modelClass" it's required.

Can i replace the source of the data instead of a model?

There is any way to pass a collection to "listRender" or similar method?

Thanks.-

Last updated

philipptempel
philipptempel

Without overwriting any of the core files (which is anyway recommended against doing), you can do that very easily by changing the model that is referenced in your config_list.yaml. Have a look at how the ListController works and you will find that it creates one or multiple Backend\Widget\Lists which, at some point in the calling, do nothing but


    /**
     * Returns all the records from the supplied model, after filtering.
     * @return Collection
     */
    protected function getRecords()
    {
        if ($this->showTree) {
            $records = $this->model->getAllRoot();
        }
        else {
            $model = $this->prepareModel();
            $records = ($this->showPagination)
                ? $model->paginate($this->recordsPerPage, $this->currentPageNumber)
                : $model->get();

        }

        return $this->records = $records;
    }

So what does that mean for you? Quite simple: Just overwrite your model such that it relates to a flat-file model or an API-model or PHP-Class model which retrieves its data from somewhere else than the database. You need to fake the query class that your model is returning such that above methods do not really change anything and then when it comes to $model->paginate() or $model->get() you simply return the data from your source of choice.

skydiver
skydiver

Hello philipptempel, thanks for your reply.

How i can "fake the query class" ? I was reading about using "newQuery" on my model, it's that ok?

I was looking the ListController class, and there is a line:

$query = $this->model->newQuery();

but can't figure how to create a "custom recordset".

Thanks.-

jacksun
jacksun

I would like to know about it too.

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.