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) Pages:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
DataMapper 1.6.0 - El Forum - 10-14-2008 [eluser]stensi[/eluser] Generally speaking, you'll always want at least one validation rule for each of your fields. I mean, if your field is a number, you should at least have 'numeric' as a rule. Likewise, if it's a varchar field, at least an 'alpha', 'alpha_numeric' or 'alpha_slash' rule. Also size constraints and so on, and even a 'trim' on all fields is a good idea. You should validate every single field. There's no telling what a malicious user might send in a doctored GET or POST request. Still, the situation of there being no rules for a field should be accommodated for, in case the developer is validating with something other than DM, and the approach I would take is basically the same as Phil's (adding missing fields from the validation array, into the validation array). Nice find by the way. I'd have never noticed since I validate everything I'll release an updated version with a fix for this but that's going to have to be the last update for a little while. I've got a lot on the next couple of days, to prepare for my flight, after which I'll be busy sight seeing! :-) So, I'm really sorry I'm not able to help out answering any of the more complicated questions. I just don't have the time right now to be able run the tests to figure out the answers, sorry :red: Version 1.4.5 has been released! View the Change Log to see what's changed. In short, doing a save() on an existing object will see changed non-validated fields updated correctly. DataMapper 1.6.0 - El Forum - 10-14-2008 [eluser]BaRzO[/eluser] @OverZealous.com sorry i haven't tell well what i need i think my models wrong... this is what i want to do maybe i can tell more better with this... Code: Links I think this is what i need i am confused to find right way Thanks for your help. <h5>Edit</h5> I have solved my problem with self referencing Thanks for your helps the example Employee is was my solution... DataMapper 1.6.0 - El Forum - 10-15-2008 [eluser]OverZealous[/eluser] @BaRzO I'm sorry, I've been really busy. I haven't had time to look over your question. Are you trying to build a recursive tree? (Meaning, one where every link can have sublinks, every sublink can have sub-sublinks, etc.) If so, that's one limitation of DataMapper - it doesn't have the ability to create that kind of recursive relationship. If your recursion is limited, then you should check out the DataMapper guide, which explains how to create Models that relate to themselves. Effectively, it requires creating subclasses that all use the same table for storage. @stensi I've been working on an interesting set of utilities. Basically, there is a slick little lazily-loaded class that allows you to output html-formatted values from a model directly. (Ex: $user->v->name would automatically escape characters.) I added a field to the validation array to handle selecting the correct type automatically ('type'). I can then easily look up both the default label and the type of output to use. Now for the important part. The validation array is not associative, which means it's difficult to find the parts for a field. I suggest you change the format to be: Code: var $validation = array( The only change needed in datamapper is in the validate() function, on line 846: Code: // CHANGED: This removes the need to loop through the array one-by-one to find the field. It doesn't affect any of the foreach() loops. If you don't want to make this change (for example, to prevent breaking existing code), you could always replace the above function with a foreach loop, which would work just as well in both cases. Code: foreach ($this->validation as $val) DataMapper 1.6.0 - El Forum - 10-15-2008 [eluser]Maxximus[/eluser] Stensi, I know you're on holiday, so just enjoy yourself now . I have a feature request, writing it now not to forget it later on.. Currently we have the option to auto_populate all related or not. Think it would be nice to have another option: auto_populate the has_one relations. This can save a huge amount of queries, doing this with a join instead of each retrieved record. It also takes away the need to do this in a foreach() loop. For instance company->country. To populate it I need to do a foreach loop, or populate it with all the different relations. I've done it now with a quick fix in __get(), but can be improved by doing it as a join. DataMapper 1.6.0 - El Forum - 10-15-2008 [eluser]BaRzO[/eluser] @OverZealous.com i was trying to recursive relations i haven't find any way after i have limited my relations to 3 level now its works. Thanks for your help DataMapper 1.6.0 - El Forum - 10-15-2008 [eluser]Boyz26[/eluser] Hi I got the following error when I first run this page, but it becomes alright once you click submit on the form. Code: A PHP Error was encountered Here's the controller Code: function slot($slot) The model: Code: <?php I have tried different ways to check if $c->error->string is present but couldn't find a way because it always has the same error of undefined stdclass. Is there any way to check if stdClass::$error is defined? Thank you! DataMapper 1.6.0 - El Forum - 10-15-2008 [eluser]OverZealous[/eluser] You aren't setting $c. You only set $c if it has a $class of 'archer' or 'warrior', but on initial page display it doesn't have a class yet, so $c is actually a string (''). Also, I'm not sure why you are running CI's validators when DataMapper automatically runs validation routines. You can simply add 'xss_clean' to the validation routine inside the model. It will run automatically on ->save() or if you call explicitly using ->validate(). DataMapper 1.6.0 - El Forum - 10-15-2008 [eluser]Boyz26[/eluser] My current dilemma is that if i use dm to do the xss validation, it will be a lot of overhead because i will be updating the database frequently. The same goes to the seperation of Archer() and Warrior(). I initially used one database Character() but decided that i could just split them to reduce resource usage. Is there any place you can point me to so that I can do more research or reading? Thank you! DataMapper 1.6.0 - El Forum - 10-15-2008 [eluser]OverZealous[/eluser] Did you read through the DataMapper docs on the first posting here? They are very good. Also, the source code is pretty easy to parse. Finally, as far as validation, if you don't change a field, then DataMapper doesn't validate the field, or update it in the database, for that matter. If you are changing a field, then the xss_clean method probably should be called, anyway, since I doubt you'd be changing it without relying on some kind of user input. (How much updating are you talking about, anyway? I mean, most modern servers can handle some processing. Are you looking at hundreds of updates per minute?) DataMapper 1.6.0 - El Forum - 10-15-2008 [eluser]Boyz26[/eluser] [quote author="OverZealous.com" date="1224119084"] Also, the source code is pretty easy to parse.[/quote] What do you mean by easy to parse? [quote author="OverZealous.com" date="1224119084"] (How much updating are you talking about, anyway? I mean, most modern servers can handle some processing. Are you looking at hundreds of updates per minute?)[/quote] I guess so. I am trying to make a game, so a user can be 'attacking', say, 10 times a minute. If there's just 20 users doing so, then it's already 200 updates on several tables. What kind of approach would you suggest to this situation? I have seperated controllers into single ones and put them into folders. Separated the table characters into tables for archers and warriors and more, so that searches and updates can be done faster (i think i read this somewhere). |