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]
  • #61 / Mar 20, 2010 12:31am

    OverZealous

    1030 posts

    @Mareshal
    I don’t know if this will help, but you need to check the return of the save function, every time.  It should always look like this:

    if($u->save()) {
        // Everything was saved OK
    } else {
        // An error occurred, check $u->error
    }

    I know the examples in the manual aren’t very clear about this, but the example application is better.  Even if you don’t use the HTMLForm extension, the pattern is the same:

    function edit($id) {
        $o = new Object($id);
        if(isset($_POST['submit'])) {
            $o->value1 = $_POST['value1'];
            if($o->save()) {
                redirect('wherever');
            }
        }
        $this->load->view('edit', array('object' => $o));
    }

    Then, in your view, you can handle showing errors.  If the item hasn’t been edited yet (ie: not submitted), there are no errors.  If it was submitted and there were no errors, the page is redirected.  If it was submitted and there are errors, then you can see them in $o->error.

    The SQL UPDATE is never run before the validation.  Validation is the first thing the save function does.

  • #62 / Mar 20, 2010 5:42am

    Buso

    297 posts

    is it possible to use this with an already existing auth library without any conflict?

  • #63 / Mar 20, 2010 1:41pm

    OverZealous

    1030 posts

    @Buso
    DMZ is not an authorization library.  It’s an ORM.  But I can’t answer yes or no, you just have to set them up and try it.

  • #64 / Mar 21, 2010 3:33am

    NachoF

    171 posts

    Im having a little problem with validation… here’s my code

    if ($this->upload->do_upload("url"))
                        {
                             $data =$this->upload->data();
                             $a->url=$data['file_name'];
                        }
                        else
                        {
                            $a->error_message('custom', $this->upload->display_errors());
                        }
                        
                        if($a->save($t))
                        {
                            $this->session->set_flashdata('success', 'Tip Creado');
                            redirect("Welcome");
                        }
                        //$a->error_message('custom', $this->upload->display_errors());  If I use it this way it works but I would preffer adding the error right after I catch it

    So want I want to do is add to the model validation errors the file upload error.. the problem is that (apparently) all errors get deleted when the save method is called… so if I set the error afterwards it does work cause it doesnt get deleted

  • #65 / Mar 21, 2010 11:47am

    OverZealous

    1030 posts

    @NachoF

    Why are you trying to save the object if there’s an error uploading?

    if ($this->upload->do_upload("url")) {
        $data = $this->upload->data();
        $a->url = $data['file_name'];
        if($a->save($t)) {
            $this->session->set_flashdata('success', 'Tip Creado');
            redirect("Welcome");
        }
    } else {
        $a->error_message('custom', $this->upload->display_errors());
    }

    Otherwise, what you are trying to do doesn’t make sense, anyway: if there are any validation errors, DMZ won’t save the object.  This means, if you set an error manually, (and the errors weren’t cleared) DMZ would never save. (That’s why it clears the errors before validating.)

  • #66 / Mar 21, 2010 3:14pm

    NachoF

    171 posts

    I try to save anyway cause I want all the errors listed in the form…. the form has many input text fields and the userfile to upload… I want the form to list all of the errors and the upload error as well….. with your code I will only get the upload error and not the rest of the errors of the form in the case that it couldnt upload the file.

  • #67 / Mar 21, 2010 3:21pm

    Mareshal

    230 posts

    Why not create a function for every step? One to check all errors, one to check upload errors, one to save the data and one to render the page back. Complicated?

  • #68 / Mar 21, 2010 3:37pm

    NachoF

    171 posts

    Why would I do that at all?? have you used datamapper error validation???... it does all of that already.. the only problem Im having is when adding a custom error.. cause when the save method is called it deletes every error for that object.

  • #69 / Mar 21, 2010 3:37pm

    Conerck

    15 posts

    I try to save anyway cause I want all the errors listed in the form…. the form has many input text fields and the userfile to upload… I want the form to list all of the errors and the upload error as well….. with your code I will only get the upload error and not the rest of the errors of the form in the case that it couldnt upload the file.

    You could try this

    // This is mostly Phil's code
    if ($this->upload->do_upload("url")) {
        $data = $this->upload->data();
        $a->url = $data['file_name'];
        if($a->save($t)) {
            $this->session->set_flashdata('success', 'Tip Creado');
            redirect("Welcome");
        }
    } else {
        // If the upload failed, this will validate the fields without saving the object
        $a->validate(); 
        // After validate has run you can append your custom errors
        $a->error_message('custom', $this->upload->display_errors());
    }
  • #70 / Mar 21, 2010 4:24pm

    NachoF

    171 posts

    Thank you that works.

  • #71 / Mar 22, 2010 12:13am

    OverZealous

    1030 posts

    Announcing DataMapper OverZealous Edition 1.7.1

    Download the Latest Version Here

      View the change log and the upgrade process
      Having issues? Please look through the Troubleshooting Guide & FAQs
      View the Complete Manual
      Search the Manual
      (Due to the server’s caching configuration, you may need to forcibly refresh your browser to see the changes in the manual.)

    Version 1.7.1:
      • Various bug fixes
      • New method for seeing if two objects are already related
      • All extensions have been updated to use or accept get_iterated
      • Please see the change log for details.

  • #72 / Mar 22, 2010 4:05am

    Mareshal

    230 posts

    woohoo, nice :D

    Congrats, I’ll definitely update my version.

  • #73 / Mar 22, 2010 5:46am

    Oblique

    32 posts

    HTML Table extension for DMZ.

    Features are:
    - label from $validation / custom label
    - mapping by $validation[‘field’][‘values’] / custom array mapping
    - custom function-generated fields
    - autopagination with native CI paginator when _paged

    ATTENTION: this extension is third-party, so don’t bother Phill with questions about it.

    Forum thread.

    Here is homebrew extension, that works in similar way as original HTML Form extension,
    but doesn’t have so much features at the moment.

    All it does is provide render_table() method that builds html code based on settings given by user. It can save some time for you and make table-generation part of the view more readable. Extension is shipped with two table templates: object_per_row and object_per_column.

    DOES NOT support _iterated at the moment.

    Docs included in distrib.

    html_table_for_dmz.zip

  • #74 / Mar 22, 2010 11:22am

    OverZealous

    1030 posts

    @Oblique
    If you have a moment, you should add your extension to the Wiki category.  The DMZ Extensions page is now linked-to from the docs, so it helps make it more discoverable.

    If you need any help making changes to support the _iterated methods, let me know!

  • #75 / Mar 22, 2010 12:22pm

    Oblique

    32 posts

    Yeah, made page, but forgot to add category.

    Damn, building docs is sooo tedious.

    I know there is way to make it fun and joyful.
    Please somebody tell me about it.
    Phill?

    Some WYSIWYG maybe? Markup by hands in NB is boring )

    @OverZealous
    Yeah, looks like now it depends almost completely on _iterated support, whether will it or will it not be needed )

    Uh. Well, i think i know how to make it work, but first i need to know that someone needs it ) Or when i will need it myself. Tired of making things just for gaining exp )

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

ExpressionEngine News!

#eecms, #events, #releases