Parsing the date from the HTML form helper

2006-12-15 Thread Rolo D. Monkey

I have this code in app/app_model.php.  It parses the separate date
fields created by $html-yearOptionTag(), $html-monthOptionTag, etc.
and formats them to be put in a DATETIME column.

It is a problem that comes up often enough that I think it might be
useful to have this somewhere in the core.  If not in Model then
somewhere in the HTML form helper.  Let me know what you think.

  function _getDate($model, $field) {

$hour = isset($this-data[$model][$field . '_hour']) ?
  intval($this-data[$model][$field . '_hour']) : null;
$min = isset($this-data[$model][$field . '_min']) ?
  intval($this-data[$model][$field . '_min']) : null;
$sec = isset($this-data[$model][$field . '_sec']) ?
  intval($this-data[$model][$field . '_sec']) : null;
$month = isset($this-data[$model][$field . '_month']) ?
  intval($this-data[$model][$field . '_month']) : null;
$day = isset($this-data[$model][$field . '_day']) ?
  intval($this-data[$model][$field . '_day']) : null;
$year = isset($this-data[$model][$field . '_year']) ?
  intval($this-data[$model][$field . '_year']) : null;

return date('Y-m-d H:i:s', mktime($hour, $min, $sec, $month, $day,
$year));

  } // end function _getDate()


--~--~-~--~~~---~--~~
 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?hl=en
-~--~~~~--~~--~--~---



Re: Saving with hasMany

2006-08-21 Thread Rolo D. Monkey

Perhaps I need to be more specific.  I am importing the data from a
.csv file, so I am building the data structure myself, and the
information from the Manual does not explain how to create a data
structure for multiple hasMany records. So far I have managed to save
Member records, and I had no trouble creating links to Categories
through a hasAndBelongsToMany association.  I have tried both

$this-Member-Individual-save($record);

and

$this-Individual-save($inds_record);

and neither worked, so there must be something wrong with my data
structure or my code.

Here is one data structure, I tried:

$record = array(
  Member=array(
id = ,
 ...
Category=array(
  Category=array(
[0] = $category_id[0],
...
  )
)
Individual=array(
  id = ,
  individual_name = $inds[$i]
)
  )
)

and it didn't work.  Also even if it did work,  what would happen if I
looped through $i?  I suspect I would end up with a bunch of duplicate
Member records.

So, I tried just saving Individuals:

$inds_record = array(
  Individual=array(
id = ,
individual_name = $inds[$i]
  )
)

and that didn't work either.  I haven't starting using
getLastInsertId() yet, but I am going to add that today, but I suspect
I am just missing something simple.  Any suggestions?


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Saving with hasMany

2006-08-18 Thread Rolo D. Monkey

I know that you cannot save associated records directly from a model
that has a hasMany relationship, but how do you do it indirectly?  I
have been all over the web for hours looking for this.

Here is a simplified version

Model Member hasMany Individual
Model Individual belongsTo Member

I am importing data and I can successfully save a new Member.  I have
an array of Individual names, but I don't know how to save them, and
keep the association intact.  Is it some variation of

$this-Member-Individual-save($record);

or do I have to declare

$uses = array(Member, Individual);

in the MembersController, and then do

$this-Individual-save($record);

If so, how do I get the id of the member I just saved?

By the way, CakePHP is awesome, and it has already saved me weeks worth
of work, but there are massive holes in the documentation on simple
stuff like this.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---