RE: Application Architecture

2006-10-26 Thread Grant Davies

 Wow, I'm loving cakePHP and have made a ton of progress.

What I'm trying to figure out now is the best approach for the
xml/view/save.

I have my xml loading and figured out and my form, I'm thinking :

A) do I use the bake utility to create a concrete version of my model
(assume to has all the data members from my table) and then :

1) read the xml
2) use the concrete version of my model and pass it to the view via the
controller
3) view uses an instance of the model to pre-populate the form
4) upon submit use the standard cake validation etc and write the model
to my database.

Or do I

B) Use the associative array version of my model and populate it with
xml :

1) read the xml
2) use the associate array version of the model and hope I spell all the
column names correctly

Steps 3  4 are same as above.


I'm a little nervous about trying to populate the dynamic model that
will be initial empty, maybe its because I come from a java background.
Is baking the model the preferred approach ?

Thoughts on this approach ?

Cheers,
Grant

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Application Architecture

2006-10-26 Thread Grant Cox

I'm not sure what you mean by baking the model - bake is just a
command line application to make model/view/controller stubs (although
stubs doesn't give them much justice, they are very functional).  Even
a complete model file will not specify the database fields, except
where needed for validation.

But anyway.  So you have your XML uploaded (and related Quicktime
files), you've parsed the XML data, and now you want to save it.
Firstly, do you really need the form before saving?  If it is just for
manual validation before the data is saved to the database, is this
really needed unless there is an error?

I would suggest that your parsing converts the XML into associative
arrays suitable for saving as model data.  Yes, this does mean that you
need to know the database field names in your parsing/conversion code,
but this isn't really that bad (you need to know the XML field/element
names too).  Rapid development is the key here, rather than over
architecting parts that aren't really likely to change.  Once you've
parsed the XML into an associative array of model data, just save it
and rely on the Model's standard validation.  If this save fails,
display an edit form just like any other edit() action, for manual
verification.

Of course, this is assuming your XML inserts only a single model row.
If it has a number of rows, then it would probably be best to parse and
validate the data, and display some kind of summary validation page to
the user.  If they continue, the file is again parsed, but the models
are saved.  This is the approach I'm using for uploading a CSV of user
data, where if there are problems it is easier for the user to
re-upload the file than to use a form to fix each row.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: Application Architecture

2006-10-26 Thread Grant Davies

Thanks Grant, that does make a lot of sense, I do display a form, the
xml usually has incomplete data that the user needs to update in the
form, so the xml is there just to seed the form.  I guess I can read
an example record from the database and then dump the associative array
to a file so I can see how to make sure I populate and empty one
correctly?  What I was looking for is best practice, i.e. do people
just look at their database and start typing into their associative
array or is there some best practice for making sure you get all your
fields correct such as dumping a record you have read from the database
?

Grant

-Original Message-
From: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Grant Cox
Sent: Thursday, October 26, 2006 7:27 AM
To: Cake PHP
Subject: Re: Application Architecture


I'm not sure what you mean by baking the model - bake is just a
command line application to make model/view/controller stubs (although
stubs doesn't give them much justice, they are very functional).  Even
a complete model file will not specify the database fields, except
where needed for validation.

But anyway.  So you have your XML uploaded (and related Quicktime
files), you've parsed the XML data, and now you want to save it.
Firstly, do you really need the form before saving?  If it is just for
manual validation before the data is saved to the database, is this
really needed unless there is an error?

I would suggest that your parsing converts the XML into associative
arrays suitable for saving as model data.  Yes, this does mean that you
need to know the database field names in your parsing/conversion code,
but this isn't really that bad (you need to know the XML field/element
names too).  Rapid development is the key here, rather than over
architecting parts that aren't really likely to change.  Once you've
parsed the XML into an associative array of model data, just save it
and rely on the Model's standard validation.  If this save fails,
display an edit form just like any other edit() action, for manual
verification.

Of course, this is assuming your XML inserts only a single model row.
If it has a number of rows, then it would probably be best to parse and
validate the data, and display some kind of summary validation page to
the user.  If they continue, the file is again parsed, but the models
are saved.  This is the approach I'm using for uploading a CSV of user
data, where if there are problems it is easier for the user to
re-upload the file than to use a form to fix each row.




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Application Architecture

2006-10-25 Thread Chris Hartjes

On 10/25/06, realien [EMAIL PROTECTED] wrote:

 I'm new to cake, but not MVC so had a few questions on where the best
 place is to put some functionality as it pertains to CakePHP.

 1) I parse an XML file from a dv camera and need to insert what I get
 into my database, I will have models for the data, but do I create my
 xml parse class in my own package and have my controller call it  and
 map it to my model somehow before inserting it into my database?  Not
 quite sure where it should fit.

You can easily create a model to do all this stuff for you.  Models in
CakePHP aren't just for database connections. :)

 2) I authenticate a user to my database and once authenticated we
 authorize the user and store their role in memory.  Do we put that in
 the session and just use it where necessary or is there a more formal
 approach for authorization ?

I'd do it in the session.  Makes total sense.

Hope that helps.


-- 
Chris Hartjes

The greatest inefficiencies come from solving problems you will never have.
-- Rasmus Lerdorf

@TheBallpark - http://www.littlehart.net/attheballpark
@TheKeyboard - http://www.littlehart.net/atthekeyboard

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Application Architecture

2006-10-25 Thread Grant Cox

That (1) is pretty much exactly what I would do.  Make a component that
parses your XML into an associative array.  Get your controller action
to pass the uploaded XML to this component, then use the array data to
create and save instances of your model(s).

I agree a lot of heavy lifting can be done in a model, but I wouldn't
put XML parsing in there as it is a generic action.


On Oct 26, 3:37 am, realien [EMAIL PROTECTED] wrote:
 1) I parse an XML file from a dv camera and need to insert what I get
 into my database, I will have models for the data, but do I create my
 xml parse class in my own package and have my controller call it  and
 map it to my model somehow before inserting it into my database?  Not
 quite sure where it should fit.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: Application Architecture

2006-10-25 Thread Grant Davies

 Thanks grant.

What I've done so far is created a controller to parse the xml, it uses
xpath to get the nodes/attributes that I need (I don't need the whole of
the xml).

No what I want to do is populate an instance of a model asset with the
contents of the nodes I captured, I see that the model is an associative
array so do I have to manually populate an associate array to be a copy
of my db table.

Any links to anything that does this ?  Basically it would be like
having a from on screen, filling it in and then creating a new record I
guess , just in my case the xml is used to pre-populate the form.

 (I have a java applet that ftp's some QuickTime files to the server
with an xml file and my cake/php app parses the xml and pre-populates a
form).

My concern here is I use cake where I can instead of just coding it
myself and slotting it into cake and not using cake's abilities.

Cheers,
Grant

-Original Message-
From: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Grant Cox
Sent: Wednesday, October 25, 2006 6:00 PM
To: Cake PHP
Subject: Re: Application Architecture


That (1) is pretty much exactly what I would do.  Make a component that
parses your XML into an associative array.  Get your controller action
to pass the uploaded XML to this component, then use the array data to
create and save instances of your model(s).

I agree a lot of heavy lifting can be done in a model, but I wouldn't
put XML parsing in there as it is a generic action.


On Oct 26, 3:37 am, realien [EMAIL PROTECTED] wrote:
 1) I parse an XML file from a dv camera and need to insert what I get 
 into my database, I will have models for the data, but do I create my 
 xml parse class in my own package and have my controller call it  
 and map it to my model somehow before inserting it into my database?  
 Not quite sure where it should fit.




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---