Entity get value |
hi sorry for english i have a model(Tratte_libere_mezziModel) with a simple sql query :
Code: $db = \Config\Database::connect(); in entity (Tratte_libere_mezzi_Entity) i have a function prezzo_sconti_maggiorazioni($id_tratte_libere_mezzi) in view in foreach loop : Code: <?php foreach ($lista as $v): ?> if i try to do $v->prezzo_sconti_maggiorazioni($v->id) Call to undefined method stdClass::prezzo_sconti_maggiorazioni() wat's wrong ?
The returned object is not your entity. If you use the model's function (find, findAll, etc) it will return the data in entity objects, but in your example you're calling the query builder, not the model's function that adds the entity automatically. If you look at the model's code, you can see it pass what you set as the return type to getResult(). So I think if you pass your entity type it would return what you expect. Something like this:
PHP Code: $res=$db->query( $sql )->getResult('App\Entities\Tratte_libere_mezzi_Entity'); ...or even better, pass the return type you already defined in your model: PHP Code: $res=$db->query( $sql )->getResult($this->returnType);
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Entity's use to change or alter or some operation before insert data in table db
Oky
Enlightenment Is Freedom
|
Welcome Guest, Not a member yet? Register Sign In |