DataMapper ORM v1.8.2 |
[eluser]tarciozemel[/eluser]
[quote author="animatora" date="1332870622"]I want an example how to query the database in the controller using datamapper and pass the result to a presenter that will format my data in a nice way, so I can easily present it in my view. I dont know how to build the presenter? Let me expand with examples: Controller: Code: $u = new User(); Presenter Code: the presenter has to have a __get() for each property of the User object View: Code: $users->name();// method from the presenter Man, is the same thing with users/cars we see before. Just change code to your model, library, helper, whatever...
[eluser]tarciozemel[/eluser]
[quote author="tarciozemel" date="1332853741"]On demand validation Hi, folks! It's possible to set "on demand validation"? I explain. The "user", in my system, have a lot of fields in the respective database and all them have their own validate rules. BUT, in the login, I only need to validate "email" and "password". So, with all that rules, when I try to perform a login, I always get validation errors, whereas DM try to validate all the fields in $validate array, not only "email" and "password". I tried "replace" the $validation array just before the validation with only that 2 rules, but without success... Any help about check only few validation rules in specifics places? Regards![/quote] My mistake. Works when we redefine the $validation array just before validation. But it's code duplication... So, the question remains: how to check only few validation rules in specifics places?!
[eluser]WanWizard[/eluser]
Validation rules in the model are meant to be used to validate the data going into the database. Meaning a completely populated object. If it's your goal to validate a few fields on a form, just use the normal form validation class.
[eluser]tarciozemel[/eluser]
[quote author="WanWizard" date="1332887194"]Validation rules in the model are meant to be used to validate the data going into the database. Meaning a completely populated object. If it's your goal to validate a few fields on a form, just use the normal form validation class.[/quote] OK, "data going into the database", but would be nice if "some/partial data into the database", too, because I believe it's a common situation what I passing right now. I have a DM "User", so, this user have email, password, first name, last name, etc. It's super practical I set all the validation rules just in one shot! BUT, in login, for example, I need to check just email & password (in my case); and, if the user pretend to change their data, that form have email, password, first name, last name, etc. So, in the login form, I need to validate just some fields, in change information form, others and so on. My suggest to DataMapper is: a third parameter in actual validate() function. In this example, could be possible code like: Code: // Validate just "email" and "password" fields What do you think? :cheese:
[eluser]tarciozemel[/eluser]
Selecting which validation rules are used at a time Hi, folks! For those who are following that "specific validation issue", I would like to contribute with this question. My idea is: set in just one place all the validation rules and pick just those are necessary at time. So, I'm creating a helper and want your help, folks! For now, its like: /application/helpers/datamapper_helper.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); So, no longer add the validation array in your DataMapper models. The "new way" would be: Code: // Already loaded the helper before... So, guys, what you think about this?
[eluser]North2Alaska[/eluser]
Background: I have two tables, contacts and methods and they have a many to many relationship. This requires a third table, contacts_methods. The methods table is a list of "methods of contact"; phone, email, IM, etc... This means the actual phone number, email address, etc... will be stored in the join table. From what I can read in the docs, the only way to set the value is using the set_join_field function. Is there any way to have the value always stored without calling the set_join_field function directly? Something I could do in the model?
[eluser]North2Alaska[/eluser]
Background: I have two tables, contacts and methods and they have a many to many relationship. This requires a third table, contacts_methods. The methods table is a list of "methods of contact"; phone, email, IM, etc... This means the actual phone number, email address, etc... will be stored in the join table. From what I can read in the docs, the only way to set the value is using the set_join_field function. I would like to create a Phone model that would have a relationship with contact that would only query the phone type method. I'm studying building advanced relationships and it seems this would be the place to put the condition. I want to do something like: Quote:class Contact extends DataMapper {I'm pretty sure this won't work, but the idea is what I would like to explore. The database model has a many to many but from the point of view of phone it's a one to many. And, in the relationship, it is defined how the table gets filtered. Also, the join_fields could also be set. I guess there needs to be a question here somewhere. :-) I just would like to know your opinion and maybe some direction as to where/how to implement something like this. Is it doable, or is it just too much outside the core of DataMapper?
[eluser]WanWizard[/eluser]
In cases where you have data in your relationship table that you need to access or update frequently, and for cases where you need a relation to the relationship table, you create a model for the relationship table, and change the relationship definitions: Contact -> has_many -> ContactMethod, and ContactMethod -> has_one -> Contact Method -> has_many -> ContactMethod, and ContactMethod -> has_one -> Method So you split the many-to-many into two one-to-many relations. This way you can use the ContactMethod model to access the fields in the relationship table directly, without using join_fields(). Any extra models that need to be related to the relationship table now be defined against the ContactMethod model. (ContactMethod is just an example, you can name the model what you want, and hard-code the table name in the model)
[eluser]North2Alaska[/eluser]
@WanWizard Very interesting and creative solution. I'll play around with it... |
Welcome Guest, Not a member yet? Register Sign In |