CodeIgniter Forums
DateTime Fields Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: DateTime Fields Problem (/thread-78408.html)



DateTime Fields Problem - thedragon655 - 01-15-2021

hello i have a problem with ci4 and datetime fields. i am using the code below





Code:
  protected $useTimestamps = true;
  protected $createdField = 'com_created_at';
  protected $updatedField= 'com_updated_at';



the comment created at and comment updated at are inserted fine in the database but when i try to display them with humanize  format it gives me an error

Call to a member function humanize() on string

the code from my view

Code:
$c->com_created_at->humanize()

ps im using different names than created_at and updated_at because i need them to be like that.


RE: DateTime Fields Problem - iRedds - 01-15-2021

Does the $c variable contain an instance of the Entity class?


RE: DateTime Fields Problem - demyr - 01-15-2021

Why don't you use normal PHP way of displaying the date?


RE: DateTime Fields Problem - thedragon655 - 01-15-2021

(01-15-2021, 11:11 AM)iRedds Wrote: Does the $c variable contain an instance of the Entity class?
yes it does contain  an entity class of comments and i display them with a join to the users table  in order to display the correct user comment


RE: DateTime Fields Problem - iRedds - 01-15-2021

(01-15-2021, 02:33 PM)thedragon655 Wrote:
(01-15-2021, 11:11 AM)iRedds Wrote: Does the $c variable contain an instance of the Entity class?
yes it does contain  an entity class of comments and i display them with a join to the users table  in order to display the correct user comment

Have you defined the $dates property of the class? As here.
PHP Code:
class User extends Entity
{
    protected $dates = ['created_at''updated_at''deleted_at'];


https://codeigniter.com/user_guide/models/entities.html#date-mutators


RE: DateTime Fields Problem - thedragon655 - 01-16-2021

(01-15-2021, 06:49 PM)iRedds Wrote:
(01-15-2021, 02:33 PM)thedragon655 Wrote:
(01-15-2021, 11:11 AM)iRedds Wrote: Does the $c variable contain an instance of the Entity class?
yes it does contain  an entity class of comments and i display them with a join to the users table  in order to display the correct user comment

Have you defined the $dates property of the class? As here.
PHP Code:
class User extends Entity
{
    protected $dates = ['created_at''updated_at''deleted_at'];


https://codeigniter.com/user_guide/models/entities.html#date-mutators


my colums are not named created_at updated_at i  named them com_created_at com_updated_at. do i have to define the names on the entity class hm really? gona test it. ps i tested still gives me the same error the only way to work is to make my column names created_at updated_at is their any fix to this?



RE: DateTime Fields Problem - thedragon655 - 01-16-2021

edit i fixed it maybe its a bug i had to do what you said in the entity class plus i had to change the getresult method to findall

return $this

->where('post_id',$post_id)
->orderBy('comments.com_created_at','DESC')
->join('users', 'comments.user_id = users.id' )
->findAll();