07.11 php saved
avairet
Tags add more
 
Note
avairet did not leave a note
  1. <?php
  2. // Modèle diaporama
  3. class Diaporama extends AppModel {
  4.  public $hasAndBelongsToMany = array
  5.     (
  6.         'Illustration' => array
  7.         (
  8.             'className' => 'Illustration',
  9.             'joinTable' => 'diaporamas_illustrations',
  10.             'foreignKey' => 'diaporama_id',
  11.             'associationForeignKey' => 'illustration_id',
  12.             'unique' => true,
  13.             'conditions' => '',
  14.             'fields' => '',
  15.             'order' => '',
  16.             'limit' => '',
  17.             'offset' => '',
  18.             'finderQuery' => '',
  19.             'deleteQuery' => '',
  20.             'insertQuery' => ''
  21.         )
  22.     );
  23. }
  24.  
  25. // Modèle illustration
  26. class Illustration extends AppModel {
  27.  public $hasAndBelongsToMany = array
  28.     (
  29.         'Diaporama' => array
  30.         (
  31.             'className' => 'Diaporama',
  32.             'joinTable' => 'diaporamas_illustrations',
  33.             'foreignKey' => 'illustration_id',
  34.             'associationForeignKey' => 'diaporama_id',
  35.             'unique' => true,
  36.             'conditions' => '',
  37.             'fields' => '',
  38.             'order' => '',
  39.             'limit' => '',
  40.             'offset' => '',
  41.             'finderQuery' => '',
  42.             'deleteQuery' => '',
  43.             'insertQuery' => ''
  44.         )
  45.     );
  46. }
  47.  
  48. // Contrôleur diaporamas_controller.php
  49. class DiaporamasController extends AppController {
  50.  public function admin_add($item_id = 0, $theme_id = 0) {
  51.   if (!empty($this->data)) {
  52.    $this->Diaporama->create();
  53.    if ($this->Diaporama->save($this->data)) {
  54.     $this->Session->setFlash(__('The Diaporama has been saved', true));
  55.     $this->redirect('/admin/items/edit/'.$this->data['Diaporama']['item_id']);
  56.    }
  57.    $this->Session->setFlash(__('The Diaporama could not be saved. Please, try again.', true));
  58.  
  59.   }
  60. $photos = $this->Diaporama->Illustration->find('all',array('fields' => array('id','name','fichier')));
  61. $this->set(compact('photos'));
  62.  }
  63. }
  64.  
  65. // Vue diaporamas/admin_add.ctp
  66. foreach ($photos as $key=>$val) {
  67.  
  68. echo '<input type="checkbox" value="'.$val['Illustration']['id'].'" name="data[Illustration][Illustration][]" />'
  69. }
  70. ?>
Parsed in 0.147 seconds, using GeSHi 1.0.7.14

Modify this Paste