[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) |
[eluser]12vunion[/eluser]
I just skip the required on ip altogether and it never fails me. My validation field: Code: 'ip' => array( And my validation rule: Code: function _get_ip($field, $parameter) { So whenever I save this model it inserts the IP address for me.
[eluser]OverZealous[/eluser]
@12vunion The only drawback to your code is you can never edit the item, or the IP address will be overwritten. If that's what you want, then fine. BDH specifically wanted it to only insert the IP address on inserts, but not change it on updates, I believe. The required is not really necessary, either way.
[eluser]BrianDHall[/eluser]
I see, I was going off this (and confused a bit more by a bug in my handling of it): Quote:Important: When cascading rules, note that rules are not run on empty fields unless the required rule is set. This includes anything that evaluates to TRUE for the empty() function, including: '', FALSE, or 0 http://www.overzealous.com/dmz/pages/validation.html I guess this means only when more than one rule is applied, or does it only apply when the custom insert rule is not the first?
[eluser]OverZealous[/eluser]
Ah, um, yeah, BrianDHall is right. Doh! That's another legacy choice from the original DataMapper that I've never been comfortable with (skipping rules if required is not set), but I can't change it because it would probably break a lot of stuff!
[eluser]BrianDHall[/eluser]
[quote author="OverZealous" date="1256684814"]Ah, um, yeah, BrianDHall is right. Doh! That's another legacy choice from the original DataMapper that I've never been comfortable with (skipping rules if required is not set), but I can't change it because it would probably break a lot of stuff![/quote] I think I'm getting the hang of this Hm, perhaps you could implement a sort of 'special_required' rule? The function would function the exact same as required in that it forced rules to be run even if the field is empty, but it would not itself trigger any error or cause form validation failure. DMZ would treat it as if required had been set (so you could probably get away with an extra OR statement wherever required is checked for), thus taking the easy way out This I suppose could always be another configurable thing, but obviously it would have to default to off or all hell would break loose when people upgraded. I have no problem with present functioning of required so far, so don't consider this a personal request The code works as I have it and I'm actually done with that system, including the confirmation email tokening and processing and everything. Damn little code for a whole lotta work - DMZ has made coding fun again for me
[eluser]OverZealous[/eluser]
[quote author="BrianDHall" date="1256686091"] Hm, perhaps you could implement a sort of 'special_required' rule? The function would function the exact same as required in that it forced rules to be run even if the field is empty, but it would not itself trigger any error or cause form validation failure. DMZ would treat it as if required had been set (so you could probably get away with an extra OR statement wherever required is checked for), thus taking the easy way out [/quote] That's exactly what I was just planning on doing! :lol: I think I'm going to add a fake "always_validate" rule, that does just that. I'm really glad to hear that it is working so well for you. The most ironic (or maybe just odd) thing about DMZ for me is that I rarely have gotten to use any new features (barring, of course, bug fixes) since about 1.3.x. I always run the latest, but I've haven't had the time to use the new features explicitly in my own code very often. That's part of the reason I wrote the example application, so I could test the new features.
[eluser]Alface[/eluser]
How can I save releated objects whith came on a array like this: Code: $_POST['videos'][1][link] = 'exemple' the database: http://img28.imageshack.us/img28/5871/db2.jpg Controller: Code: $va = new Videosalbum($id); On my view I have a JS script for create as much inputs the user needs.. (it is called on 'type' => 'links' on VideosAbum Model) Code: <input type="text" value="" id="videos[1][link]" name="videos[1][link]"/> 'VideosAbum' Model Code: class Videosalbum extends DataMapperEx { 'Video' Model Code: class Video extends DataMapperEx { The erro: Code: A PHP Error was encountered What is the best pratice for this task? Thanks
[eluser]OverZealous[/eluser]
@Alface The from_array method is shorthand for converting basic forms (and arrays). If you are trying to save something outside of that simple scope, you need to manually look up the objects you want to save. Simply create an array of DMZ objects, and save those normally. Also, your error is in your controller, it is a PHP error, and it means you are trying to access a property on a non-object. A non-object is any value that isn't an instantiated object, including NULLs.
[eluser]BrianDHall[/eluser]
[quote author="OverZealous" date="1256686707"][quote author="BrianDHall" date="1256686091"] Hm, perhaps you could implement a sort of 'special_required' rule? The function would function the exact same as required in that it forced rules to be run even if the field is empty, but it would not itself trigger any error or cause form validation failure. DMZ would treat it as if required had been set (so you could probably get away with an extra OR statement wherever required is checked for), thus taking the easy way out [/quote] That's exactly what I was just planning on doing! :lol: I think I'm going to add a fake "always_validate" rule, that does just that. I'm really glad to hear that it is working so well for you. The most ironic (or maybe just odd) thing about DMZ for me is that I rarely have gotten to use any new features (barring, of course, bug fixes) since about 1.3.x. I always run the latest, but I've haven't had the time to use the new features explicitly in my own code very often. That's part of the reason I wrote the example application, so I could test the new features.[/quote] I think its natural, as I don't know that I've used any of the new features either, but I keep up on updates just in case. Meanwhile lots of other people use them, so they must be important. Perhaps we just work on different problems, or knowing the inherant annoyances of trying to do things certain ways we (consciously or not) redirect our train of thought to find others way of doing it that don't run into such obstacles. Hell, until DMZ I never normalized a database because I didn't want to have to mess with such things. Now I'm friggin' learning join statements and advanced SQL syntax and built-in functions, though I never intended to do so. New tools to manage complexity permit greater complexity to be managed, after all. Ultimately you have a very well fleshed out core with years of wishing for extra features built up and taken care of. I've yet to run into a major bug, so its pretty damn stable. I have trouble of thinking of things I wish it did, except outside its core scope and into the scope of extensions to the core. That of course may change as my proficiency increases and I am encouraged to push the limits of the system, but its a damn good core you have to work with.
[eluser]Alface[/eluser]
[quote author="OverZealous" date="1256698999"]@Alface The from_array method is shorthand for converting basic forms (and arrays). If you are trying to save something outside of that simple scope, you need to manually look up the objects you want to save. Simply create an array of DMZ objects, and save those normally. Also, your error is in your controller, it is a PHP error, and it means you are trying to access a property on a non-object. A non-object is any value that isn't an instantiated object, including NULLs.[/quote] And when I call a object like this: Code: $u = new User(); I'm not putting more than one user on a single object without creating a array of objects? Thanks |
Welcome Guest, Not a member yet? Register Sign In |