Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Field with data type TIME
  • Fatal Error!



    ErrorException [ Fatal Error ]:
    Method
    Fuel\Core\Date::__toString() must not throw an exception, caught
    Fuel\Core\PhpErrorException: A non well formed numeric value encountered



    PKGPATH//orm/classes/model.php @ line 0

    <br />
    <b>Fatal error</b>: Method Fuel\Core\Date::__toString() must not throw an exception, caught Fuel\Core\PhpErrorException: A non well formed numeric value encountered in <b>C:\saas\api.payroll\fuel\packages\orm\classes\model.php</b> on line <b>0</b><br />

    In orm/classes/model.php line 2167 - 2169 I added these:

    echo
    gettype($val), ': ', $key, ' => ';
    print_R($val);
    echo PHP_EOL;

    and the result:

    object: start_time => Fuel\Core\Date Object
    (
    [timestamp:protected] => 05:00:00
    [timezone:protected] => Europe/Berlin
    )

    caused by line 2167:

    $val = (string) $val;

    called from find() with options['related']. The related table has start_time with data type TIME. No $_properties defined in related table.

    The error above does not occur if I define $_properties in related model.

    FuelPHP version is 1.9

  • HarroHarro
    Accepted Answer
    How can a timestamp be a string with "05:00:00:? A timestamp is a number...
  • This is the result of show create table calendar_schedules:
    CREATE TABLE `calendar_schedules` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `calendaritem_id` int(11) NOT NULL,
      `start_time` time NOT NULL,
      `end_time` time DEFAULT NULL,
      `duration` int(11) DEFAULT NULL
      PRIMARY KEY (`id`)
    )

    and this is for select start_time, end_time from calendar_schedules limit 10:
    +------------+----------+
    | start_time | end_time |
    +------------+----------+
    | 19:00:00   | NULL     |
    | 20:00:00   | NULL     |
    | 21:00:00   | NULL     |
    | 22:00:00   | NULL     |
    | 23:00:00   | NULL     |
    | 00:00:00   | NULL     |
    | 01:00:00   | NULL     |
    | 02:00:00   | NULL     |
    | 03:00:00   | NULL     |
    | 04:00:00   | NULL     |
    +------------+----------+
    10 rows in set (0.00 sec)

    this is model/calendar/schedule.php

    class Model_Calendar_Schedule extends Orm\Model
    {
        protected static $_belongs_to = array('calendaritem');

        protected static $_observers = array('Orm\\Observer_Typing');
    }

    model/visitlogs.php

    class Model_Visitlog extends Orm\Model
    {
        protected static $_belongs_to = array('calendar_schedule');

        protected static $_observers = array('Orm\\Observer_Typing');
    }

    controller/visits.php

    class Controller_Visits extends Controller_Rest
    {
        protected $format = 'json';

        public function get_index()
        {
            $this->options = array(
                'related' => array(
                    'calendar_schedule'
                )
            );

            $id = Input::get('id', 'all');

            $visits = Model_Visitlog::find($id, $this->options);

            $result = $visits->to_array();

            //$this->>response($result);
        }
    }

    the request: GET /visits?id=1

    PHP version is 5.6/7.2
  • HarroHarro
    Accepted Answer
    The problem is that you haven't defined your properties in the model, so the ORM tries to determine them by requesting column data from your database.

    And for some reason the ORM sees your "time" column as datetime, upon which the Typing Observer tries to convert it to a Date object, which fails.

    I'll have a look at it.
  • HarroHarro
    Accepted Answer
    I've pushed an update to the ORM package for Observer_Typing, with support for the database column types DATE, TIME and DATETIME.

    Let me know if this fixes your problem.
  • It does fixed the problem. Thanks!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion