Welcome Guest, Not a member yet? Register   Sign In
DateTime Fields Problem
#1

(This post was last modified: 01-15-2021, 06:39 AM by thedragon655.)

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.
Reply
#2

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

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

(This post was last modified: 01-15-2021, 02:37 PM by thedragon655.)

(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
Reply
#5

(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/model...e-mutators
Reply
#6

(This post was last modified: 01-16-2021, 06:12 AM by thedragon655.)

(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/model...e-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?
Reply
#7

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();
Reply




Theme © iAndrew 2016 - Forum software by © MyBB