Welcome Guest, Not a member yet? Register   Sign In
date auto getter in Entity ignore my date format
#7

(This post was last modified: 09-18-2020, 01:42 PM by nicojmb.)

(09-18-2020, 01:10 PM)InsiteFX Wrote:
(09-18-2020, 11:06 AM)nicojmb Wrote: hi, i try to do the same but does't work, can you share you working code?

Regards!

PHP Code:
The $useTimestamps automatically fills the $date array with the $createdField $updatedField and the $deletedFields

So set this to true.


PHP Code:
/**
 * If true, will set created_at, and updated_at
 * values during insert and update routines.
 *
 * @var boolean
 */
 
protected $useTimestamps false

Not work, i use custom model extended from MyTh.

I have tried everything, $useTimestamps to "true", $useTimestamps to "false", with $dates array, etc...

PHP Code:
namespace App\Models;

use 
Myth\Auth\Models\UserModel as BaseModel;

class 
UserModel extends BaseModel
{  

    
protected $dates = [];

    protected $returnType = \App\Entities\User::class;

    protected $useTimestamps true;


PHP Code:
namespace App\Entities;

use \
Myth\Auth\Entities\User as BaseEntity;
use 
CodeIgniter\I18n\Time;

class 
User extends BaseEntity
{

    public function getUpdatedAt(string $format 'd/m/y H:i')
    {
        $this->attributes['updated_at'] = $this->mutateDate($this->attributes['updated_at']);

        $timezone $this->timezone ?? app_timezone();

        $this->attributes['updated_at']->setTimezone($timezone);

        return $this->attributes['updated_at']->format($format);
    }

    public function getCreatedAt(string $format 'd/m/y H:i')
    {
        $this->attributes['created_at'] = $this->mutateDate($this->attributes['created_at']);

        $timezone $this->timezone ?? app_timezone();

        $this->attributes['created_at']->setTimezone($timezone);

        return $this->attributes['created_at']->format($format);
    }


PHP Code:
"title""Exception",
    
"type""Exception",
    
"code"500,
    
"message""DateTime::__construct(): Failed to parse time string (15/09/2020 17:43:11) at position 0 (1): Unexpected character",
    
"file""/var/www/vhosts/nicojmb.com/yani.nicojmb.com/vendor/codeigniter4/framework/system/I18n/Time.php",
    
"line"138
Reply


Messages In This Thread
RE: date auto getter in Entity ignore my date format - by nicojmb - 09-18-2020, 01:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB