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 - 02-26-2009 [eluser]tdktank59[/eluser] The validation errors are from the form validation... not datamapper i found the problem after I started looking lol... DataMapper 1.6.0 - El Forum - 02-27-2009 [eluser]cberk[/eluser] I'm somewhat new to CI and DM, but you guys have accelerated my learning curve tremendously, so thanks. I'm working on a project in DM and am enjoying it a lot, but right now I'm stumped. I have some custom validation functions that need to be available to multiple models, so I need to either extend the DM library or edit it to include my functions. Obviously I would prefer the former. So I made my own library and saved it to the libraries folder as mydatamapper.php, and extended the DM library like so: Code: class MyDataMapper extends DataMapper Then I pointed all of my models to the new library: Code: class Client extends MyDataMapper { Unfortunately, I am getting an error that says "An Error Was Encountered. Unable to load the requested class: Datamapper". This is the first time I have tried to extend a non-native library, and I'm not sure what I'm doing wrong. Any pointers would be greatly appreciated. DataMapper 1.6.0 - El Forum - 02-27-2009 [eluser]OverZealous[/eluser] @cberk: You almost have it! Instead of making it a library, place your extension in the models directory. Then, just add DataMapper (and not your new model) to your autoloads. You can extend it the same way, and it will be autoloaded by DataMapper just fine. I recommend everyone set up DataMapper this way. You almost always will end up extending it in some way! PS: if you want to make your code more flexible, change your constructors to this (PHP5 only): Code: function __construct() This allows you to easily change your base class! DataMapper 1.6.0 - El Forum - 02-27-2009 [eluser]cberk[/eluser] Thanks, OverZealous! Let me make sure I have this straight. My extension mydatamapper.php should be saved to the application/models folder, and be constructed something like this: Code: class MyDataMapper extends DataMapper { My other models should extend DataMapper, not MyDataMapper: Code: class Client extends DataMapper { I'm not sure exactly what you mean by [quote author="OverZealous.com" date="1235737577"]@cberk: Then, just add DataMapper (and not your new model) to your autoloads.[/quote] DataMapper is already autoloaded in my application/config/config.php file, so does that mean I'm set? It seems logical that I would need to edit the DataMapper library in some way for it to find my extension. Am I on the right track or am I missing something? Thanks for your help! DataMapper 1.6.0 - El Forum - 02-27-2009 [eluser]OverZealous[/eluser] Sorry to be confusing, you still need to subclass MyDataMapper, not DataMapper. Code: class Client extends MyDataMapper { Then leave DataMapper in application/config/autoload.php, but make sure that MyDataMapper is never autoloaded. When DataMapper starts up, it automatically includes all of the models in the application/models folder, so MyDataMapper will get loaded. Good Luck! DataMapper 1.6.0 - El Forum - 02-27-2009 [eluser]cberk[/eluser] That fixed it! Thanks! DataMapper 1.6.0 - El Forum - 02-27-2009 [eluser]quasiperfect[/eluser] hi in the datamapper config i have auto_transaction set to true i'm traing to create a user asignit to a group and based on a value $i create 1 or 2 profiles this action has to be executed all or at all when i run my code i always get Code: A PHP Error was encountered.Severity: Notice.Message: Undefined property: stdClass::$transaction the user get's saved but nothing else any tips ? in my controller i have Code: $u = new User(); DataMapper 1.6.0 - El Forum - 02-27-2009 [eluser]stefanv[/eluser] Today i found out that the was a little bug in the way errors are stored in the 'validation' function in combination with the 'error_message' function. So i made a patch against the datamapper library file for the 'error_message' function to fix it. This patch changes one thing: you can get 'all' errors per field and not only the last one! - $object->error->fieldname now gives an array back instead of a string. - $object->error->all & $object->error->string are not changed ! Code: /** DataMapper 1.6.0 - El Forum - 02-27-2009 [eluser]OverZealous[/eluser] @quasiperfect You probably do not have a field named "transaction" on your object. @stefanv While I like your idea, it would break a lot of existing code that expects a string on the fields. Why are you getting multiple errors per field? I'm pretty sure DataMapper's validation routine stops as soon as any field has an error. DataMapper 1.6.0 - El Forum - 02-27-2009 [eluser]quasiperfect[/eluser] what do u mean "transaction" field ? i'm refering to this http://stensi.com/datamapper/pages/transactions.html and any idea about the really important thing "i’m traing to create a user asignit to a group and based on a value $i create 1 or 2 profiles this action has to be executed all or at all" thanks in advance |