Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $_POST = {
- user = {
- username: zeelot3k
- password: awesomesauce
- // Alias that is in the user model that points to user_profile model
- profile = {
- name: Lorenzo Pisani
- address: 550 awesome street
- aim: zeelot3k
- }
- }
- }
- $user = ORM::factory('user');
- // this is the array of values that will be set
- $expected = array(
- 'username',
- 'password',
- // ORM will automatically look for related models
- 'profile' => array(
- // Notice that the address will not be saved
- 'name',
- 'aim',
- ),
- );
- $user->values($_POST['user'], $expected);
- try{
- $user->save();
- }catch (ORM_Validation_Exception $e){
- $errors = $e->errors();
- }
- // the errors array will look something like this (including an example with many to many errors)
- $errors = {
- user: {
- username: 'This field is required.'
- password: 'This field must be at least 6 characters long.',
- profile: {
- aim: 'This is not a valid AOL AIM screen name.'
- }
- occupations: [
- {
- 'job_title': 'This is not a valid job title',
- 'description': 'This field is required'
- },
- {
- 'job_title': 'This field is required'
- },
- ]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement