Welcome Guest, Not a member yet? Register   Sign In
Class 'Locale' not found
#1

Dear All,

Actually I'am trying to get created_at and updated_at from my model

PHP Code:
$model->created_at 

But I got error "Class 'Locale' not found", I search a lot about this, and I sow it's some thing regarding "intl extension" in php environment, I tried a lot to install it with mac xampp 7.4.4, but with no result.

Any Idea how I can call created_at and updated_at from my model without getting this error?

Thanks
Reply
#2

Any updates developers ?
Reply
#3

You need to show the code you're using before advice can be offered.
Reply
#4

(05-26-2020, 06:05 AM)dave friend Wrote: You need to show the code you're using before advice can be offered.


In my Entity:

PHP Code:
<?php namespace App\Entities;

use 
CodeIgniter\Entity;
use 
CodeIgniter\I18n\Time;

class 
Task extends Entity
{


    
    
public function getUpdatedAt(string $format 'Y-m-d H:i:s')
    {
        // Convert to CodeIgniter\I18n\Time object
        $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);
    }

    
    
    



In my Controller:
PHP Code:
<?php

namespace App\Controllers;
use 
App\Controllers\BaseController;
use 
App\Models\TasksMD;

class 
Tasks extends BaseController
{
    
    
private $tasksMD;
    
    
    
function __construct()
    {
        $this->tasksMD  =  new TasksMD();
    }
     
    
    
    
    
public function get()
    {
        $this->data['tasks']     =   $this->tasksMD->findAll();

        return view('view',$this->data);
    }


In My Model:
PHP Code:
<?php

namespace App\Models;
use 
CodeIgniter\Model;

class 
TasksMD extends Model
{
 
 
    
        
protected $table                =   'tasks';
        protected $primaryKey           =   'sid';
        protected $returnType           =   'App\Entities\Task';
        protected $useTimestamps        =   true;
        protected $allowedFields        =   ['staff','title','details','isInterview','person',
                                             'contact','time','date','status','addedByUser'];        

   
        


In My View:

PHP Code:
foreach($tasks as $key => $task)
  {
    ?>
          <tr>    
                <td><? echo $key+1 ?></td>                                            
                 <td><? echo $task->updated_at ?></td>            
          </tr>
     <?
   } 
Reply
#5

(This post was last modified: 05-26-2020, 09:37 AM by vitnibel.)

This error occurs if there is no installed intl extension specified in the system requirements.

Server Requirements

Class Locale
Reply
#6

(05-26-2020, 09:35 AM)vitnibel Wrote: This error occurs if there is no installed intl extension specified in the system requirements.

Server Requirements
 I search a lot about this, and I sow it's some thing regarding "intl extension" in php environment, I tried a lot to install it with mac xampp 7.4.4, but with no result.

Any Idea how I can call created_at and updated_at from my model without getting this error?
Reply
#7

If, with the constructor of the Time class, all parameters are passed explicitly, then most likely the call to the Locale :: getDefault () function due to which an error occurs can be avoided.

PHP Code:
class Time {
public function 
__construct(string $time null$timezone nullstring $locale null)
    {
        
// If no locale was provided, grab it from Locale (set by IncomingRequest for web requests)
        
$this->locale = ! empty($locale) ? $locale Locale::getDefault();

Reply
#8

(05-26-2020, 09:59 AM)vitnibel Wrote: If, with the constructor of the Time class, all parameters are passed explicitly, then most likely the call to the Locale :: getDefault () function due to which an error occurs can be avoided.

PHP Code:
class Time {
public function 
__construct(string $time null$timezone nullstring $locale null)
    {
        
// If no locale was provided, grab it from Locale (set by IncomingRequest for web requests)
        
$this->locale = ! empty($locale) ? $locale Locale::getDefault();


What I should to do now?
Reply
#9

Do not call the function mutateDate(), but create the Time object explicitly based on the data format in the database.
For example, this way you can avoid calling a function of the Locale class.
PHP Code:
$this->attributes['created_at'] = new Time($this->attributes['created_at'], 'UTC''en-US'); 
Reply
#10

(05-26-2020, 10:34 AM)vitnibel Wrote: Do not call the function mutateDate(), but create the Time object explicitly based on the data format in the database.
For example, this way you can avoid calling a function of the Locale class.
PHP Code:
$this->attributes['created_at'] = new Time($this->attributes['created_at'], 'UTC''en-US'); 

Now I got diffrent error (Class 'IntlDateFormatter' not found)


PHP Code:
public function __toString(): string
1316     
{
1317         return IntlDateFormatter::formatObject($this->toDateTime(), $this->toStringFormat$this->locale);
1318     
Reply




Theme © iAndrew 2016 - Forum software by © MyBB