Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Orm Observer (CreatedAt, UpdatedAt) in package model
  • Hi,

    I generated a model with oil and moved it to a package. The problem is, that the created_at and updated_at fields remains 0 on insert and on every save event.

        protected static $_observers = array(
            'Orm\\Observer_CreatedAt' => array(
                'events' => array('before_insert'),
                'mysql_timestamp' => false,
            ),
            'Orm\\Observer_UpdatedAt' => array(
                'events' => array('before_save'),
                'mysql_timestamp' => false,
            ),
        );
  • How do you use this model, because packages don't have support for controllers and models.
  • I added the model in the package bootstrap file:

    'Auth\\Model_User'    => __DIR__.'/classes/model/user.php',


    Everything works fine excluding the observers.
  • This is the standard Auth package? Which is aliased to global?

    And you're using $user = Model_User::forge() or $user = \Auth\Model_User::forge() ?
  • This package is an other package, which has the Auth namespace. I call this extauth, this will be a driver to the auth package. All the classes and models are in the Auth namespace.

    In the bootstrap of my package I load the auth package to make sure that it is loaded. I am using Model_User without the Auth namespace, because the classes I use it in are in the Auth namespace as well.

    But I pushed the code to github.
    https://github.com/sagikazarmark/fuel-extauth

    Bookmarks for you:

    Bootstrap
    User creation
    User Model

    I tried putting '\\' before the Orm in the observers array, but did not work. I don't really understand this. I am sure this is my fault, but I can't find the bug.
  • HarroHarro
    Accepted Answer
    Debug the ORM model class, which is what calls the observers.
  • Hi,
    I finally found it, but this is rather the error of the generation. I used oil to generate my model. As you can see, created_at and updated_at are not in the property list. This is how the oil generated it. When I add the created_at and updated_at properties to the model property list, everything works fine.

Howdy, Stranger!

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

In this Discussion