Closed
Description
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