Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition)

[eluser]OverZealous[/eluser]
[quote author="12vunion" date="1252571970"]Again, you're the man. Any chance of you sending me the update? I didn't see a link to your repo posted anywhere.[/quote]

It's a private repository (in-house, literally :lol: ).

I've attached the updated datamapper.php, though. Just replace the one in your /libraries/ folder. It has not been thoroughly tested, so use at your own risk ;-)

[eluser]12vunion[/eluser]
Wunderbar! Thanks!

[eluser]emorling[/eluser]
When I load an object to change a property and save it, all it's relationships are lost in the relationship table. Any idea what I'm doing wrong?

$char = new Char();
$char->get_by_id(1);
$char->gold = 10;
$char->save();

At this point all the items that my char has is lost, and also the records in the relationship table have been removed.

[eluser]OverZealous[/eluser]
[quote author="emorling" date="1252684631"]When I load an object to change a property and save it, all it's relationships are lost in the relationship table. Any idea what I'm doing wrong?[/quote]

No. The code, as you posted it, works. You must have done something different or configured something incorrectly somewhere else.

Do a little debugging, check the queries that are being run. You probably can figure it out from there.

[eluser]BrianDHall[/eluser]
@emorling: I would suggest you closely check your models and database, with special emphasis on naming, spelling, and whether or not you are using the singular or plural forms of your models/tables.

[eluser]demogar[/eluser]
I think I'm doing something wrong, but I can't get it working.

I want to register a user ONLY when the user submits but it happens inmediatelly I access the page.. and the validation is not working at all.

Controller:
Code:
function create()
    {
        // Loader
        $this->load->helper('form');
        #---
        
        # Header
        $header = array(
                'title'        =>    'Create user',
                'description'    =>    'bla bla'
            );
        $this->load->view('header.html', $header);
        
        # Body
        $this->load->view('user/create.html');
        
        # Footer
        $this->load->view('footer.html');
        
        if ($this->input->post('username') !== FALSE):
            
            #
            $u = new User();
            
            $u->username    = $this->input->post('username');
            $u->name    = $this->input->post('name');
            $u->lastname    = $this->input->post('lastname');
            $u->email    = $this->input->post('emnail');
            $u->password    = $this->input->post('password');
            $u->password2    = $this->input->post('password2');
            $u->user_type    = $this->input->post('user_type');
            
            if ($u->save()) {
                echo 'user registered';
            } else {
                echo '<h3>Error...</h3>';
                echo '<p>' . $user->error_string . '</p>';
            }
        endif;
    }

Model:
Code:
class User extends DataMapper
{

    var $validate = array(
            'username'    => array(
            'label'    => 'Nick',
            'rules'    => array('required', 'trim', 'unique', 'alpha_dash', 'min_length' => 3, 'max_length' => 20)
        ),
            'name'        => array(
                'label'    => 'Name',
                'rules'    => array('required', 'trim')
            ),
            'lastname'    => array(
                'label'    => 'Lastname',
                'rules'    => array('required', 'trim')
            ),
            'email'    => array(
                'label'    => 'E-mail',
                'rules'    => array('required', 'trim', 'valid_mail')
            ),
            'password'    => array(
                'label'    => 'Password',
                'rules'    => array('required', 'md5')
            ),
            'password2'    => array(
                'label'    => 'Password confirmation',
                'rules'    => array('required', 'matches' => 'password')
            ),
            'user_type'    => array(
                'label'    => 'User or admin?',
                'rules'    => array('required')
            )
        );
}

Any help is really appreciated. I'm new with this and I have around 1 hour trying to make it work... I know how to do this using the form_validation library and the AR from CI, but I'm getting some troubles with this with DMZ + its validation.

Thank you in advance Smile

[eluser]OverZealous[/eluser]
[quote author="Demostenes Garcia" date="1252714141"]I want to register a user ONLY when the user submits but it happens inmediatelly I access the page.. and the validation is not working at all.[/quote]

First off, your error string is referring to a non-existent variable ($user instead of $u). That's probably part of it.

Second, for some reason you are printing content above the save attempt. (Maybe that's on purpose. Usually one performs the save attempt first, then prints out content.)

Third, please look at the included examples in the documentation. I've got examples of how to generate a form and save it using the included HTMLForm and Array extensions. If you don't like using the extensions, I think I've got examples on this forum (yeah, it's long) and elsewhere in the docs that can help.

Also, double-check all of your variable names and model information. It isn't that hard, and in fact is a lot simpler than using Form_Validation and AR manually.

But the validation rules do work. ;-)

[eluser]demogar[/eluser]
Nevermind... I found the error.. please, don't laugh Tongue

Code:
var $validate = array( .. );

Instead of:
Code:
var $validation = array( .. );

[eluser]OverZealous[/eluser]
For future reference, there's a template model included with DMZ you can use to jumpstart a new class. It has a lot of the variables pre-defined (often commented out), so it helps with these sorts of typos!

Good job finding it, though.

Edit: The template is located at <dmz zip>/application/models/_template.php

[eluser]Blaze Boy[/eluser]
i have upgraded my project Vunsy to the latest DMZ instead of DM ,
http://ellislab.com/forums/viewthread/128510/
have a look and tell me what's your opinion




Theme © iAndrew 2016 - Forum software by © MyBB