CodeIgniter Forums
DataMapper 1.6.0 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: DataMapper 1.6.0 (/showthread.php?tid=11358)



DataMapper 1.6.0 - El Forum - 10-02-2008

[eluser]Isuka[/eluser]
Thanks for your response stensi. In fact I'm doing error validation (my error messages are on the view). But when I submit my form, its return TRUE, so I don't have errors. That's the weird thing, all my others fields are updated correctly, only the "is_published" field is not updated. And the same thing happen if, for exemple, I fill my "lastname" field width a 0, save() return TRUE but nothing updated in my database. I think that the save() method don't want a value of 0.


DataMapper 1.6.0 - El Forum - 10-02-2008

[eluser]Iverson[/eluser]
Thanks. I was going in the direction of the third example but I couldn't quite get the syntax and call right. I think that is the best solution, seeing that #1 would put all your errors in one place, and there's no way to know which ones to echo, unless you're going to tell me that it would just be an empty string. If that's the case, that would be perfect, since I like to do client-side validation as well.


DataMapper 1.6.0 - El Forum - 10-02-2008

[eluser]stensi[/eluser]
@Isuka: Ah, I see. Thanks for pointing that out! In the _to_array() method, it ignores a property value if it is considered empty(), which a 0 is. I'll fix it up, run some tests, then have version 1.3.2 up soon.

@Iversion: Yep, for #1, if there were no errors it'll just be an empty string. You can still go with any of the 3 ways as it does an empty string for each thing if its corresponding property had no errors.


DataMapper 1.6.0 - El Forum - 10-02-2008

[eluser]Isuka[/eluser]
Great. Another little thing I have noticed. If I make validation rules like this :
Code:
var $validation = array(
    array(
            'field' => 'lastname',
            'label' => 'Nom',
            'rules' => array('required')
        ),
        array(
            'field' => 'firstname',
            'label' => 'Prénom',
            'rules' => array('required', 'matches' => 'lastname')
        )
);
My error messsage will look like this :
Code:
Le champ Prénom doit correspondre au champ lastname
Is it possible to get the label value ("Nom") instead of the field value ("lastname") ?


DataMapper 1.6.0 - El Forum - 10-02-2008

[eluser]stensi[/eluser]
Version 1.3.2 has been released!

View the Change Log to see what's changed.

In short, I fixed the _to_array() method so it returns all properties (including zero, NULL and empty strings) except when getting by objects properties ($object->validate()->get()) so you can now save zero's, NULL's and empty strings. I also corrected validation error messages to show the label if a field name is used as a parameter.

@Isuka: That's something I've noticed as well, and am working to rectify. I'll look at it tomorrow if I have the time. I'm a bit short on it tonight and don't want to rush a hacky fix on that one, since I want to solve that sort of issue for any validation rule, not just the 'matches' rule.

UPDATE

I fixed the matches rule thing Isuka mentioned and have bundled it into 1.3.2.


DataMapper 1.6.0 - El Forum - 10-02-2008

[eluser]Isuka[/eluser]
I have just install datamapper 1.3.2 and it seems there is a problem with the get() method. When I loop through $obj->get()->all, all my ID field are the same. Sorry to give you some work again Smile


DataMapper 1.6.0 - El Forum - 10-02-2008

[eluser]stensi[/eluser]
I had a brainstorm on how to fix that "matches" error thing so I just bundled it into version 1.3.2.

As for getting the same ID for everything, you're probably not using the right object in your foreach loop. I just did a clean install of DataMapper and ran all the example code and everything works correctly.

Can you post your code so I can have a look?


DataMapper 1.6.0 - El Forum - 10-02-2008

[eluser]Isuka[/eluser]
You are right, my old model class was loaded in my controller, making some conflict :red:

I think there is the same problem of the empty value for the get() method. My field "is_published" is now updated correctly with a 0 but when I do a $obj->get(), $obj->is_publish is empty.


DataMapper 1.6.0 - El Forum - 10-02-2008

[eluser]stensi[/eluser]
Ah, sorry. I should've noticed a similar change would be required in the _to_object() method. Could you redownload version 1.3.2 and try again? I just bundled the fix for that into it.


DataMapper 1.6.0 - El Forum - 10-02-2008

[eluser]Isuka[/eluser]
It works fine now Smile

Just one more thing, I can't make work xss_clean in my validation rules. When I put this rule I got a fatal error :
Code:
Fatal error: Call to a member function xss_clean() on a non-object in applications/backend/models/datamapper.php on line 1853
All others rules work great except this one.