Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition)

[eluser]matt_n[/eluser]
Perfect! Thanks so much, works a treat.
I tip my hat to you...

[eluser]tolyx[/eluser]
Nice one OZ - this is a really great piece of work.

I'd love to automatically create form elements from objects... is this possible? I'd love to use a Django like framework without having to learn Django... ;-)

[eluser]OverZealous[/eluser]
I don't know the first thing about Django! Tongue

DataMapper is primarily (solely?) a ORM (Object-Relational Mapper), and it is only concerned with getting information in and out of the DataBase.

If I ever get my next big update out (and it will probably be a little while), I'll have the ability to extend DataMapper in a clearly specified and shareable manner. Then it might be possible to add something like a scaffold for those who want it.

The alternative would be to build a lightweight scaffold around DM. Someone else would have to do that, however. ;-P

I already use some custom tools to kinda do this, but here's some hints for someone who wants to try:

1) I include an additional element in my Validation rules called 'type', and I assign that a value like 'line', 'text', 'checkbox', 'select', etc. You could name this whatever you want. This helps generate the correct control.

2) I have a library that, when given a DM Object and field name, converts that field into HTML markup. (Mine is extremely specific, however, because I am relying on the Dojo JavaScript framework for client-side processing.) You should pay attention to certain rules, such as 'max_length' and use these to customize the form.

3) If you wanted to automate this, you would need too loop through the validation rules, and generate a HTML for each one ('id', of course, would become a hidden input).

4) The real problem comes from the relationships, which would be interesting to see someone solve in an automated manner.

[eluser]NachoF[/eluser]
Hey phil, do you happen to know if datamapper (and dmz) work with postgresql?... Ill probably start a project with postgresql and would love to use datamapper.

[eluser]OverZealous[/eluser]
@NachoF
LOL: PostGreSQL is all I use. Works fine. If you have any trouble, make sure you are using the latest version of CodeIgniter (because it has had some trouble in the past).

[eluser]Daniel H[/eluser]
Does it matter? Planning a big project with with SQL Server (!) soon - that should be okay, right?

[eluser]OverZealous[/eluser]
@Daniel H

In theory, anything that CodeIgniter uses should work 100%. CodeIgniter doesn't actually contain any SQL code. The only reason you might have trouble is if a feature isn't supported by CI for your DB engine.

Since I have no way to test SQL Server, I would really appreciate any bug reports or feedback if you have problems!

[eluser]Daniel H[/eluser]
I have no idea how I'll test the application!! ;-) Weird client request. Will be in touch...!

[eluser]NachoF[/eluser]
thanks Phil... I hate thinking of having to program without using some kind of ORM....
I agree with tolyx, I would love to be able to use form_dropdown with datamapper... something like
Code:
$student=new Student();
$student->get()
//and then be able to use
form_dropdown('student',$student->all)

[eluser]matt_n[/eluser]
@NachoF
Quote:I agree with tolyx, I would love to be able to use form_dropdown with datamapper… something like

Don't know whether this is the kind of thing. I created a library for a selectbox class. You basically point it at a model and it bases the drop down menu on the model.

So you'd write:

Code:
$select = new Selectbox('Section'); // This creates the instance of the selectbox based on the section model from my application
$select->draw(); // This echos the HTML to the page

This is the quickest way to do it, and relies on the class defaults which are 'id' for the value and 'label' for the label. I find a lot of my tables have a label column. You might want to change the class default for that if your tables tend to have another common field. Or just say:

Code:
$select = new Selectbox();
$select->model('User'); // Make a drop down menu of the User model
$select->label('username'); // Column to use as the display text for the options. Defaults to 'label' column
$select->value('user_id'); // Defaults to id
$select->condition('activated','1');// Make a drop down of only active users
$select->draw(); // Echo the HTML

also supports method chaining:

Code:
$select = new Selectbox('User');
$select->label('username')->condition('activated','1')->draw();

Other options are styles: array of CSS styles to add to the field, classname: CSS class name, disabled, multiple, size.

Don't know if it will help, but thought I'd post it up here because it seemed relevant!

Class is attached if anyone's interested. I keep it in my application/libraries folder.
Cheers,
Matt




Theme © iAndrew 2016 - Forum software by © MyBB