DMZ 1.7.1 (DataMapper OverZealous Edition) |
[eluser]OverZealous[/eluser]
@Benedikt Just so you know - you can use where_related, you just have to call it after include_join_fields, like so: Code: $n->include_join_fields()->where_related($x)->get_iterated()
[eluser]jpi[/eluser]
Hi, I think I am going to extend DMZ using the PHP native inheritance mechanism (ie class DataMapperExt extends DataMapper {). Line 421 of DMZ rev 395 there are these lines : Code: $this_class = strtolower(get_class($this)); This means, that for my object that will instanciate my DataMapperExt class, $is_dmz will be set to false. Thus _load_languages() method will not be called. So I will have to call _load_languages manually in the constructor of my child class. In my opinion, line 421 should be replaced by : $is_dmz = $this instanceof DataMapper; OR $is_dmz = is_a($this, 'DataMapper'); It shouldn't break anything.
[eluser]TheJim[/eluser]
@jpi I also extend DataMapper, and there's no need to do what you're proposing. When CI loads the library ($this->load->library('datamapper') or in your autoload config), the DataMapper class is instantiated and that code runs as it should. If you make your change, then you will run code for every DMZ model instantiation that only needs to run once when the library itself is loaded.
[eluser]jpi[/eluser]
I agree because you said : Quote:When CI loads the library ($this->load->library(‘datamapper’) or in your autoload config), the DataMapper class is instantiated What if I want to do $this->load->library(‘DataMapperExt’) (my child class) or autoload DataMapperExt in my config file ? I think that scenario makes sense and in that case a problem will arise, but I am not sure since I have not tested yet. Edit : Humm I see now what you meant by Quote:If you make your change, then you will run code for every DMZ model instantiation that only needs to run once when the library itself is loaded. This means that, I have no other option than to autoload the original DataMapper and then make my model extends DataMapperExt. It's a bit weird but it's okay.
[eluser]TheJim[/eluser]
In my case, what I actually do is use a CI pre-system hook to set up my own custom autoloader. If something extends my equivalent of your DataMapperExt, then when the autoloader is called for DataMapperExt, I load the database and DMZ if they're not loaded yet. That way I can call new Model() wherever I want it and have everything just work without necessarily including the database and DMZ on every page (they're relatively heavy libraries).
[eluser]jpi[/eluser]
I see but in your case, what class do your models extend ? The original DMZ or your custom class ?
[eluser]TheJim[/eluser]
They extend my custom class (although I also check for DataMapper load in case I happen to have a model that extends DataMapper directly). Since it's my own simple autoloader, it doesn't really matter, because I know what needs to be loaded to make it work. I'm not saying you have to do it this way, of course, but for me, that makes loading my models very convenient.
[eluser]Atas[/eluser]
Hello ! I am working with datamapper validation and i am using the function "set_value()" to return the input values when an error is shown, but isn't working , nothing is returned! Code: <input name="username" value="<?php echo set_value('username'); ?>" /> If i skip the validation with $object->skip_validation()->save() set_value() function works. Any idea ? Sorry my english!
[eluser]OverZealous[/eluser]
@Atas DMZ doesn't work with the built-in form methods, necessarily. The recommended way to use DMZ with forms it to follow this pattern: Code: $object = new Object($object_id); In view: Code: <input name="username" value="<?php echo $object->username ?>" /> This allows you to use the same code to output both the current content and the modified content. |
Welcome Guest, Not a member yet? Register Sign In |