[Deprecated] DMZ 1.6.2 (DataMapper OverZealous Edition) |
[eluser]OverZealous[/eluser]
@someoneinomaha Save yourself the trouble, check out Deep Relationships
[eluser]Oblique[/eluser]
@NachoF, i don't like per-method authorization too. That's why i use AOP-like feature (make some coffee, so you don't accidently fall asleep while reading this): 1) we implement our own "template" controller in libraries folder, "MY_Controller", from which our other controllers descend. 2) in MY_Controller's constructor we define $this->current_user (i use tank_auth, but don't like it much, though it's not bad) and analyse uri - basing on what segment(1) is set to, we decide, if this section is accessible by current_user or not. 3) After it, if you have to restrict users from some particular methods, access to which depends on user's behaviour, you could do this in same MY_Controller's contructor. My implementation of this approach looks like this: Code: MY_Controller.php Code: user.php If you have nested directories of controllers, this would look a bit more complicated around that line where current controller and method is defined
[eluser]The Hamburgler[/eluser]
Quick question. - Need to display a table of filtered dm records - There are +1000 records in the db so the table needs to be paged. - The table is dynamically filtered by post/session data So far my code looks like this: Code: ... Controller This code will not work because after count() is called the sql clauses set by filter() will be lost. If I comment out $this->contact->count(); and use count($this->contact->all) instead the maximum count possible will be 20. I'm looking for a elegant way to retrieve both a full count of filtered records and a paged subset of filtered records without having to call filter twice. Any ideas???
[eluser]OverZealous[/eluser]
@The Hamburgler Look back about 2 pages. This was just discussed in the last week, and I provided a couple of solutions. Why wouldn't you call filter() twice? The call to filter is probably a several order-of-magnitudes faster than the actual queries. Also, Don't manually load models! DM automatically handles loading all of the models, so you should never, ever make a call to $this->load->model().
[eluser]The Hamburgler[/eluser]
Oops, now I feel bad. Thanks a lot. At the moment filter() is also doing some work prepping data for the filter view. Calling it twice would be a waste. There's an argument for splitting these two behaviours into different methods, which I may do eventually. I'm using global instances of datamapper models in my controller most of the time, so calling $this->load->model('contact') instantiates $this->contact automatically. I guess i'll just do $this->contact = new Contact(); instead from now on.
[eluser]OverZealous[/eluser]
The Hamburgler The latter would be more efficient (new Contact()), simply because you are otherwise re-loading the PHP file each time. It's probably almost insignificant in the overall speed.
[eluser]beemr[/eluser]
First off, great library. I used to use Active_Record_Mod but I am loving the thought that you've put behind this. So now to my problem. I have a custom validation on an unrequired field so it is set to "always_validate". Since the field isn't required, it's initial value in the database is NULL. Now, even if the field is left empty, it will overwrite the NULL to '' upon calling save(). All subsequent attempts to run the custom validation will fail since datamapper will unset unchanged values (as it should). To solve for this, I added a check against NULL stored values when the submitted value is empty. Added at line 1002 of datamapper.php: Code: if ($this->{$field} === $this->stored->{$field} || This way I can freely update the whole model without breaking my custom validation rule. What do you think? (For what it's worth, the custom rule created a requirement dependency based on the value of another field.)
[eluser]OverZealous[/eluser]
@beemr I cannot find that line, since the upcoming version of DMZ I'm working on has a lot of changes. Which method was that in? (Also, you could just manually set the value of the field to NULL in your custom field if you want it NULL.) Update Oops, I accidentally my verb.
[eluser]beemr[/eluser]
The field in question is a textarea, so NULL is not available as a preset value. I added the NULL check in the function: function save($object = '', $related_field = '') Here's some of the context code: Code: // Convert this object to array |
Welcome Guest, Not a member yet? Register Sign In |