Skip to content

Automatic Entity cast for Parser #2317

Closed
@SteeveDroz

Description

@SteeveDroz

Describe the bug
Passing an Entity to the Parser displays an ErrorExceptions: Object of class (…) could not be converted to string

CodeIgniter 4 version
v4.0.0-rc.2.1

Affected module(s)
Entity or Parser, couldn't tell

Expected behavior, and steps to reproduce if appropriate
Currently, in order to be able to pass an entity to the parser, one must do the following:

// Entity:
namespace App\Entities;

class Article extends \CodeIgniter\Entity
{
    protected $casts = [
        'options' => 'array'
    ];

    // …
}

// Controller:
$article = …; // from the model or whatever
$parser = \Config\Services::parser();
$parser->setData(['article' => $article->options])->render('article.html');

It would be so convenient if the Entity class didn't need such a cast and if, when passed to a Parser, it was automatically cast into usable data.

Currently, the code below returns an ErrorException because you can't convert an Entity into a string. That simple way of doing would be very useful, though:

// Entity: nothing in particular!

// Controller:
$article = …; // from the model or whatever
$parser = \Config\Services::parser();
$parser->setData(['article' => $article])->render('article.html'); // or with compact('article')

Context

  • OS: Linux Fedora 30
  • Web server Apache 2.4.41
  • PHP version 7.3.10

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions