ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

DMZ 1.7.1 (DataMapper OverZealous Edition)

March 14, 2010 11:43pm

Subscribe [104]
  • #346 / Jun 17, 2010 2:05pm

    zombaya

    5 posts

    Hi, I’m experiencing something weird and I don’t know how to solve it.  I get an error-report when trying to update an object.

    The code I’m trying to run:

    $v = new vak();
    $v->where('id',$vakid)->get();
    $v->heeft_student = true;
    echo $v->naam;
    $v->save();

    The result and errormessage I’m getting:

    keuzevak: objectgericht progr.  // This is the correct result for $v->naam
    Fatal error: Class name must be a valid object or a string in ...\application\libraries\datamapper.php on line 2418

    How the model ‘vak’ is setup:

    class vak extends DataMapper{
        var $table = "vakken";
        var $has_many = array(
                "les" => array(
                                'class' => 'les',
                                'other_field' => 'vak'
                ),
                "student" => array(
                                'class' => 'student',
                                'other_field' => 'vak'
    
                )
        );
        var $has_one = array(
                "docent" => array(
                                'class' => 'docent',
                                'other_field' => 'vak'
                ),
                "klas" => array(
                                'class' => 'klas',
                                'other_field' => 'vak'
    
                )
        );
    
        var $validation = array(
            array(
                'field' => 'naam',
                'label' => 'Vaknaam',
                'rules' => array('required', 'trim', 'min_length' => 3, 'max_length' => 50)
            ),array(
                'field' => 'klas',
                'label' => 'Klas',
                'rules' => array('required')
            ),array(
                'field' => 'docent',
                'label' => 'Docent',
                'rules' => array('required')
            ),
            array(
                'field'    => 'heeft_student',
                'label' => 'heeft studenten',
                'rules' => array()
            )
            );
    }

    Am I doing something wrong or is this a bug?

  • #347 / Jun 17, 2010 2:47pm

    OverZealous

    1030 posts

    @zombaya
    Please see the troubleshooting guide.  This question is answered there.

  • #348 / Jun 17, 2010 3:18pm

    zombaya

    5 posts

    That was indeed my problem, thank you very much.  I’ll look there first the next I encounter something like that.

  • #349 / Jun 19, 2010 2:08pm

    Skipper

    6 posts

    I am using jQuery.tools for forms validation before handing the form over to DMZ for validation. Any DMZ validation erros go back to jQuery validation for showing the error messages.

    It would be good to have the field name plus the error message from $dmz->error->all, ie. I would prefer to access this like

    foreach($si->error->all as $field => $error) { ...

    From what I see, slightly changing the DMZ function error_message($field, $error) (line 2599) to

    $this->error->all[$field] = $this->error->{$field};

    does what I want. Do you see any hidden side-effects? So far, everything continues to work as before, but there may be some condition where this breaks things. Any idea?

    Thanks for DMZ, Phil! Great work!

  • #350 / Jun 19, 2010 11:38pm

    OverZealous

    1030 posts

    @Skipper
    That seems safe - I’ll look into it when I get time to update DMZ next.

    You can also easily do this:

    foreach($si->error as $name => $value) {
        if($name != 'all' && $name != 'string') {
            ...
        }
    }

    It’s not as clean, since you have to exclude the all and string fields.  Also, your way is a lot easier if you are trying to export the error object as a JSON object.

  • #351 / Jun 20, 2010 6:42am

    Skipper

    6 posts

    Indeed, with the small change, this works perfectly well for me:

    echo(json_encode($wc->error->all));

    Thanks!

  • #352 / Jun 21, 2010 2:20am

    Skipper

    6 posts

    It seems that enum’s are not mentioned anywhere. I googled both this thread and the documentation: Nada

    This is probably something for the DMZ wishlist: Having enum validation and an array of enum-permitted-values of a field. Or maybe I am blind, and everything is already there?

  • #353 / Jun 21, 2010 8:17am

    OverZealous

    1030 posts

    @Skipper

    This is PHP, not Java 😉

    If you want to validate an input, just set up a custom validation rule.  There’s really not any reason for DMZ to have more specialized support than that.

  • #354 / Jun 21, 2010 8:39am

    Skipper

    6 posts

    This is PHP, not Java 😉

    Lol, true. Actually, I was musing over MySQL’s enum as in

    CREATE TABLE foobar ...
    `unit` enum('box','pcs','kg','gr','ml','l','m','cm','mm','hrs','min') NOT NULL,
    ...

    where I considered DMZ closer to validate. Your (deprecated) forms library knew about enums for drop-downs, IIRC, so I stupidly believed that DMZ would also.  :red:

    Anyway. Custom validation does this nicely as well, although not as DRY as I have hoped.

    Cheers!

  • #355 / Jun 21, 2010 9:43am

    OverZealous

    1030 posts

    @Skipper

    Sounds like that would be a great case for a DMZ extension.  Seeing as that is a MySQL-only feature (and I don’t use MySQL in my own apps 😛 ), it wouldn’t work as part of the core library.

    However, you could most likely code that as an extension, and it would be highly reusable.  For example, if the method was called rule_enum, it could handle looking up the enum values, and doing the checking.  (You’d probably want to cache the results of the enum lookup somehow.)

  • #356 / Jun 22, 2010 7:01am

    happydude

    45 posts

    Errm

    Noob DMZ question: If my model is user, should the file be saved as user.php or user_model.php?

    If its meant to be user.php, will it still work if I save it as user_model.php?

  • #357 / Jun 22, 2010 7:08am

    happydude

    45 posts

    And errmmm… another noob question (cause I’m starting to really get into databases and ORM), for DataMapper, which engine is better: MyISAM or InnoDB.

    This is because DataMapper tries to emulate the foreign key capabilities of InnoDB

  • #358 / Jun 22, 2010 2:56pm

    jpi

    55 posts

    @happydude

    Regarding your naming problem, why don’t you try both and see what’s working ? Then, if you still don’t know the answer, try to read the awesome documentation of DMZ. OverZealous put a lot of effort on it.

    The MyISAM vs InnoDB problem is complicated. As a quick answer, I would say that it doesn’t matter at an early stage of developpment and small DB size.

  • #359 / Jun 22, 2010 3:25pm

    happydude

    45 posts

    As per my first question, I was still reading the documentation for the first time and kinda missed the part about naming… There’s no need to be sarcastic. Its a matter of posting an answer if you have it.

    For the second question, the DB is not small… and I am still modelling it, so I need to know what works best with DMZ before I start any coding at all.

    Thank for your help all the same.

  • #360 / Jun 22, 2010 3:51pm

    OverZealous

    1030 posts

    @happydude
    I don’t think that jpi was being sarcastic.  I think he was letting you know that the docs explain the naming convention.  You kinda need to expect a little bit of that if you ask beginner questions before reading the documentation, though.  😉

    As far as DB type - DMZ doesn’t care which type of DB you use.  I’m not a big MySQL user, but if I remember correctly you don’t get proper transactions unless you use InnoDB.  For any application bigger than a simple website, transactions really are the difference between a web toy and a safe app for multiple users..  You should double check which table type, though.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases