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

[eluser]warrennz[/eluser]
Thanks again Over Zealous

And quite right, I have a validation rule setup like that for it. I did have a really strange problem with it however. If I entered nothing into the confirm_username input field, once the form was posted, it would take on the value of my username field. Only after I added a 'required' rule to the confirm_username rule did it work as one might expect. Dunno if that's a bug, my code, or my browser being silly with cache/cookies/session or whatever but yea.

So not sure how I'm gonna get around that one in future Smile

Thanks again Tongue

[eluser]OverZealous[/eluser]
Not a bug. If you don't include 'required', and the field is empty, DataMapper doesn't process any rules — since many of the rules might fail on an empty field (like exact_length).

However, if you do include 'required', when saving an object it might throw an error if that field is empty.

This is mitigated on one rule only: 'matches'. DataMapper has a special provision to pre-fill in the other field if a field has the 'matches' rule.

One way to avoid it (I have used) is to create a custom _required function just for the model that needs it. This method (if only used on one field) can simply return TRUE, or it can return TRUE by checking the passed in field:

Code:
// in User, for example
function _required($field, $param) {
    if($field == 'custom_username') {
        return TRUE;
    } else {
        return parent::_required($field, $param);
    }
}

[eluser]oddman[/eluser]
[quote author="OverZealous.com" date="1241578970"]@NachoF
And I wouldn't use RoR for real applications, either. Tongue That's partly what drew me to CodeIgniter. (That, and, while I've always been a Java developer, web development in Java has just gotten too complicated for its own good. Duplicating all your declarations in XML = Sick )

My point is that not everyone wants an ORM, and CodeIgniter's optional ActiveRecord already handles a lot of what RoR makes so special.[/quote]

Define "real application", because I can tell you right now that Rails powers some of the largest websites. Point of my post is, your framework of choice matters not, it's what you do with it. You could have the lightest framework in the world, but if you're not cacheing properly, your entire application will fall over once you hit 50+ requests/sec.

Fyi, I helped build a site that serves millions of users/day, using RoR for Westfield Group. I've also done similar with Cake and CI - so it's not the framework that matters.

[eluser]OverZealous[/eluser]
Good for you.

[eluser]oddman[/eluser]
Well if you're going to slam frameworks, you need to back yourself boi Wink

[eluser]OverZealous[/eluser]
Lighten up, that original statement wasn't targeted personally at you. This is a forum about CI, not RoR. I don't have to back anything up, anyway, because I was giving my reason for choosing CI. For goodness sake, I followed it with a smiley.

Please troll elsewhere ;-P

[eluser]oddman[/eluser]
Moving to PM Wink

[eluser]warrennz[/eluser]
Help Smile

I have my user validation set like so

Code:
array(
    'field'    => 'password',
    'label'    => 'Password',
    'rules'    => array('required','min_length' => 8)        
),
array(
    'field'    => 'confirm_password',
    'label'    => 'Password Confirmation',
    'rules'    => array('matches' => 'password')        
),

but it does not validation a match.. at all. The validation passes when the password field prams are met.
Here's my controller
Code:
$u = new User();
$u->password = $this->input->post('password');
$u->confirm_password = $this->input->post('confirm_password');

if(!$u->save())
{
    echo $u->error->string;
}
else
{
       echo 'Success';
}


Any ideas?

Thanks

[eluser]warrennz[/eluser]
Double posting for the win Smile

I'm trying to extend DMZ. This is my datamapperext.php

Code:
/**
* Data Mapper Extended Class
*
*/

//Grab base DM library
include(APPPATH.'libraries/datamapper'.EXT);

/**
* Data Mapper Class
*/
class DataMapperExt extends DataMapper {
    
    function DataMapperExt()
    {
        parent::DataMapper();
    }
    
    /**
     * Turns a result set into a simple dropdown list with the key as the row id, and the value being the selected fields value.
     * You can also specific to have the first <option> blank with the 2nd paramer
     *
     * @param string $field
     * @param bool $add_blank
    
    function droplist($field,$add_blank = false)
    {
        foreach($this->all as $r)
        {
            echo $r->id; //Do something
        }
    } */
}

/* End of file datamapperext.php */
/* Location: ./application/models/datamapperext.php */

This is my model
Code:
class Account extends DataMapperExt  {
    
    var $has_one = array("user");
    
    /**
     * Constructor
     *
     * Initialize DataMapper.
     */
    function Account()
    {
        parent::DataMapperExt();
    }
}

My autoload config is loading 'datamapperext'

I'm getting

A Database Error Occurred

Quote:Error Number: 1146

Table 'datamapperexts' doesn't exist

SELECT * FROM `datamapperexts` LIMIT 1

Something somewhere is going screwy with the table names etc. I'm really not sure

Any ideas would be appreciated Smile

Thanks

[eluser]OverZealous[/eluser]
@warrnennz

Second things first:

Do not include the DataMapper model in the DME class. Simply create the DataMapperExt class as a model (NOT as a library). Load the DataMapper library like normal, through the autoloader (and do not load the DataMapperExt at all, as DataMapper will load DME automatically). Also, make sure you don't load any models, as DataMapper loads all of the models automatically, and including anything in the models will just duplicate the loading of classes (and, possibly, cause bugs).

You should not get any errors with DataMapper unless you try to instantiate DataMapperExt — which you also should never do.

Also, this might help, but don't use parent:Big GrinataMapper (or parent:Big GrinataMapperExt). Instead, create the constructor using standard PHP constructors:
Code:
function __construct() {
    parent::__construct();
}

This is how mine is, and I know it works without errors.

The 'matches' problem:

I don't know why you are having trouble with the example given. You might want to try doing some debugging first. The only difference between the example you gave and mine is that I include 'trim', and an 'encrypt' function (as recommended in the instructions). Also, as I said before, if you do not manually check for 'required' (and do not include the 'required' validation rule), the 'confirm_password' field will always pass when empty().

Please try to debug by adding some echo()s to the DataMapper validation code, to see what's going on.




Theme © iAndrew 2016 - Forum software by © MyBB