We are currently building an application using Flash and CakePHP.  We
have an online form built using Flash, which submits its contents to
the system via a CakePHP script.

The database consists of the following design:
pages:
  id
  book_id
  title
  template_id
  template_url
  page_no

images:
  id
  page_id
  url
  x_axis
  y_axis

pages_images:
  page_id
  image_id

There is a many-to-many relationship between the images and pages
tables.  This relationship is described in the Page model with the
following code:

var $hasAndBelongsToMany =
  array('Image' => array(
     'className' => 'Image',
     'joinTable'  => 'pages_images',
     'conditions' => '',
     'order' => '',
     'limit' => '',
     'uniq' => true,
     'dependent' => true,
     'deleteQuery'=> '',
     'finderSql'  => '',
     'foreignKey' => 'page_id',
     'associationForeignKey' => 'image_id'));

Because we are using Flash to submit the form, we cannot use the
htmlHelper classes, and therefore must construct the POST variables
manually in Flash.  The Flash application allows the user to create a
new page for a book, select a template for the page, and add multiple
images into the page.  Once submitted, PHP will save all this
information into the database described above.

The parameters we pass to CakePHP are as follows:
save?data[Page][page_no]=1&data[Page][template_id]=5&data[Page][template_url]=template/mask5.swf&data[Page][title]=Page1&data[Image][Image][0][url]=pic0.jpg&data[Image][Image][0][_x_axis]=10&data[Image][Image][0][y_axis]=-50&data[Image][Image][1][url]=pic0.jpg&data[Image][Image][1][x_axis]=10&data[Image][Image][1][y_axis]=-50

This produces the following array in Cake:

Array
(
   [Page] => Array
        (
            [page_no] => 1
            [template_id] => 5
            [template_url] => template/mask5.swf
            [page_title] => Page1
        )

    [Image] => Array
        (
           [0] => Array
           (
               [url] => pic0.jpg
               [x_axis] => 10
               [y_axis] => -50
           )

           [1] => Array
           (
               [url] => pic0.jpg
               [x_axis] => 10
               [y_axis] => -50
           )
        )
)

However, when I try to submit the Flash form, I receive the following
error:

Notice: Array to string conversion in
D:\development\ebookMaker\cake\libs\model\model_php5.php on line 928

In addition, I see the following output in the DEBUG output:

DELETE FROM `pages_images` WHERE page_id = '71'  0  2
INSERT INTO `pages_images` (page_id,image_id) VALUES ('71',Array)

We've been trying to submit different combinations of arrays and
parameters, however CakePHP never manages to insert the new Image
records into the database and create the necessary links to the page
via the pages_images table.

Can someone help me?  What exactly is wrong with the array I am using
to pass the image data to the PHP program?  Why are the parameters I am
passing causing an 'Array to string conversion' error?  I've tried
several array formats, but none of them seem to work properly.

In addition, it seems that CakePHP assumes that a record of the image
already exists in the images table, and is simply inserting the
image_id and page_id values into the pages_images table.  When what it
should be doing is first inserting the image data into the images
table, grabbing the newly inserted image's record ID and then use that
to insert the information into the image_id field in pages_images
table.  Is this possible in CakePHP at the moment?  Or do I need to
override the model's save function with customized code in order to
achieve this type of functionality?

Thanks,
StinkyD


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

Reply via email to