Thanks for the reply but thats not what Im looking for really.
Perhaps you don't understand what I'm trying to achieve. I want to add a
gallery, so I have three fields in this table as follows:
Gallery Table
ID | Gallery_name | Caption
I then have an images table which is related to the gallery table this is
the structure :
Images Table
ID | gallery_id | gallery_name | caption
What I want to do is get the galleryid to be inserted into the images
table, through a form, which you can see above once a gallery is added it
redirects to images/add, I want to get the last inserted id into the form
in the images/add form so that I am able to call on the related ones
Any help would be appreciated greatly
Thanks
On Wednesday, 18 July 2012 13:51:54 UTC+1, Guti Grewal wrote:
>
> Hi Im trying to create an image gallery with CakePHP 2.1, I'm having a
> little bit of trouble with the complexity of the task.
> I have two tables, Galleries and the other Images. My galleries controller
> is like this...
> <?php
> class GalleriesController extends AppController {
> public $name = 'Galleries';
> function add() {
> if($this->request->is('post')) {
> if($this->Gallery->save($this->request->data)) {
> $this->Session->setFlash('Your gallery has been saved. You may upload
> pictures to this gallery');
> $this->redirect(array('controller' => 'images','action' => 'add'));
> } else {
> $this->Session->setFlash('Unable to add your gallery.');
> }}}}?>
>
> Once I get redirect to the images/add I want the form to have the id of
> the gallery as well as the name of the gallery within this form.
>
> How do I go about achieving this?? Anyone have any ideas?
>
> This is what I have for my view in images/add, however this is not working
>
> <div class="maincontent">
> <?php echo $this->Form->create('Image',
> array('controller'=>'Images','action'=>'add','type' => 'file',
> 'class'=>'uploadfrm'));?>
> <fieldset class='registerf'>
> <legend class='registerf2'>Upload a Picture for gallery</legend>
> <?php
> echo '<br/>';
> echo '<br/>';
> echo $this->Form->input('galleryid', array('between'=>'<br />', 'class' =>
> 'input', 'value' => $this->Gallery->id));
> echo $this->Form->input('gallery_name', array('between'=>'<br />',
> 'class'=>'input', 'value' => $galleries['galleryname']));
> echo $this->Form->input('caption', array('between'=>'<br />', 'rows'=>
> '7', 'cols'=> '60', 'class'=>'input'));
> echo $this->Form->input('team_relating', array('between'=>'<br />',
> 'class'=>'input'));
> echo $this->Form->input('team_relating_two', array('between'=>'<br />',
> 'class'=>'input'));
> echo $this->Form->input('league', array(
> 'options' => array('premiership',
> 'laliga','seriea','championsleague'),
> 'empty' => '(choose one)'
> ));
> echo $this->Form->input('file', array('type' => 'file'));
>
> echo "<br/>";
> ?>
> <?php echo $this->Form->end(__('Upload Photo', true));?>
> </fieldset>
> </div>
> This is also my controller for the Images
>
> <?php
> class ImagesController extends AppController {
> function add() {
> if($this->request->is('post')){
> $file = $this->request->data['Image']['file'];
> if($this->Image->save($this->data) &&
> move_uploaded_file($file['tmp_name'],APP.'webroot/files/galleries'.DS.$this->Image->id.'.jpeg'))
> {
> $this->Session->setFlash('<p class="uploadflash">The upload has been
> saved</p>', true);
> $this->redirect(array('controller'=>'Images', 'action' => 'add'));
> } else {
> $this->Session->setFlash('<p class="loginerror">The upload could not be
> saved, jpeg files can be processed only.</p>', true);
> }}
> $galleries = $this->Image->Gallery->find('list');
> $this->set(compact('galleries'));
> }}
> ?>
> Would appreciate any help!!
>
> Thanks!
>
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php