Welcome Guest, Not a member yet? Register   Sign In
issue with validation with datamapper
#11

[eluser]johnmerlino[/eluser]
Thanks for response. I actually got things working but I wanted to clean it up a little so I added the magic method __set:


Code:
//controller
            $user->password($this->input->post('password'));
            $user->confirm_password($this->input->post('confirm_password'));


//User model
            protected $password;
            protected $confirm_password;

            public function __set($property,$value){
                $method = "set_{$property}";
                if(method_exists($this, $method)){
                    return $this->$method( $value );
                } else {
                    $this->$property = $value;
                }
            }
        
            public function set_password($pass){
                $this->password = $pass;
            }
            
            public function set_confirm_password($confirmed_pass){
                $this->confirm_password = $confirmed_pass;
            }

The above raises this:

Code:
Fatal error: Uncaught exception 'Exception' with message 'Unable to call the method "password" on the class User' in /Users/johnmerlino/Sites/hmla/system/application/libraries/Datamapper.php:1210 Stack trace: #0 /Users/johnmerlino/Sites/hmla/system/application/controllers/passwords.php(13): DataMapper->__call('password', Array) #1 /Users/johnmerlino/Sites/hmla/system/application/controllers/passwords.php(13): User->password('') #2 [internal function]: Passwords->update() #3 /Users/johnmerlino/Sites/hmla/system/codeigniter/CodeIgniter.php(236): call_user_func_array(Array, Array) #4 /Users/johnmerlino/Sites/hmla/index.php(115): require_once('/Users/johnmer...') #5 {main} thrown in /Users/johnmerlino/Sites/hmla/system/application/libraries/Datamapper.php on line 1210
#12

[eluser]WanWizard[/eluser]
Code:
$user->password($this->input->post('password'));
calls a method called 'password', which does not exist. That's what the error message says...

Datamapper captures calls for unknown methods, that's how it deals with all where_... variations, so that's why you get this error message instead of the standard PHP error.
#13

[eluser]johnmerlino[/eluser]
[quote author="WanWizard" date="1306016787"]
Code:
$user->password($this->input->post('password'));
calls a method called 'password', which does not exist. That's what the error message says...

Datamapper captures calls for unknown methods, that's how it deals with all where_... variations, so that's why you get this error message instead of the standard PHP error.[/quote]

Now let's say you didn't have a database table and you didnt have a model, because for one form submission, all it is intended to be is a contact us, where the information gets sent to the admin user in an email, but nothing gets stored in data table. Yet, you have your typically input fields that will get passed into an email. How is one supposed to validate those input fields if you dont have a database table or model for the form?
#14

[eluser]WanWizard[/eluser]
Use CI's form validation library, that what it's there for.




Theme © iAndrew 2016 - Forum software by © MyBB