when i put the  die(debug($this->data)); i get the following error.

*app\controllers\areas_hazards_controller.php* (line *23*)

Array
(
    [AreasHazard] => Array
        (
            [area_id] => 22
            [hazard_id] => 15
            [Control] => Array
                (
                    [0] => 13
                )

        )

)


//-----//-----//-----//-----//-----//--
Controllers---//-----//-----//-----//-----//-----//-----//


find below my code



<?php
class AreasHazardsController extends AppController {

    var $name = 'AreasHazards';
    var $helpers = array('Html', 'Form');

    function index() {
        $this->AreasHazard->recursive = 0;
        $this->set('areasHazards', $this->paginate());
    }

    function view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid AreasHazard.', true));
            $this->redirect(array('action'=>'index'));
        }
        $this->set('areasHazard', $this->AreasHazard->read(null, $id));
    }
function add() {
         $hzds = $this->AreasHazard->Hazard->findall();
         $this->set('hzds',$hzds);
        if (!empty($this->data)) {
         die(debug($this->data));
            $this->AreasHazard->create();
            if ($this->AreasHazard->save($this->data)) {
            if($this->AreasHazard->saveAll($this->data, array('validate' =>
'first'))){
                $this->Session->setFlash(__('The AreasHazard has been
saved', true));
                $this->redirect(array('action'=>'index'));
            }} else {
                $this->Session->setFlash(__('The AreasHazard could not be
saved. Please, try again.', true));
            }
        }
        $hazards = $this->AreasHazard->Hazard->find('list');
        $areas = $this->AreasHazard->Area->find('list');
        $controls = $this->AreasHazard->Control->find('list');
        $this->set(compact('hazards', 'areas', 'controls'));

    }


    function edit($id = null) {
         $hzds = $this->AreasHazard->Hazard->findall();
         $this->set('hzds',$hzds);
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid AreasHazard', true));
            $this->redirect(array('action'=>'index'));
        }
        if (!empty($this->data)) {
            if ($this->AreasHazard->save($this->data)) {
                $this->Session->setFlash(__('The AreasHazard has been
updated', true));
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The AreasHazard could not be
updated. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->AreasHazard->read(null, $id);
            $hazards = $this->AreasHazard->Hazard->find('list');
        $areas = $this->AreasHazard->Area->find('list');
        $controls = $this->AreasHazard->Control->find('list');
        $this->set(compact('hazards','areas','controls'));
        }

    }


    function delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for AreasHazard',
true));
            $this->redirect(array('action'=>'index'));
        }
        if ($this->AreasHazard->del($id)) {
            $this->Session->setFlash(__('AreasHazard deleted', true));
            $this->redirect(array('action'=>'index'));
        }
    }

}
?>




//-----//-----//-----//-----//-----//-- Models
---//-----//-----//-----//-----//-----//-----//

<?php
class AreasHazard extends AppModel {

    var $name = 'AreasHazard';
    var $primaryKey = 'area_id';
    var $validate = array(
        'hazard_id' => array('numeric'),
        'area_id' => array('numeric'),
        'control_id' => array('numeric')

    );


    function beforeValidate() {
    // join hobbies into csv
    if(!empty($this->data['Areashazard']['controls'])) {
        $this->data['Areashazard']['controls'] = join(',',
$this->data['Areashazard']['controls']);
    }

    return true;
}

    //The Associations below have been created with all possible keys, those
that are not needed can be removed
    var $belongsTo = array(
        'Hazard' => array(
            'className' => 'Hazard',
            'foreignKey' => 'hazard_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'Area' => array(
            'className' => 'Area',
            'foreignKey' => 'area_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),

'Control' => array(
            'className' => 'Control',
            'foreignKey' => 'control_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

}
?>


//-----//-----//-----//-----//-----//-- add.ctp
---//-----//-----//-----//-----//-----//-----//

<div class="areasHazards form">

<?php echo $form->create('AreasHazard');?>
    <fieldset>
         <legend><?php __('Add Hazard to Area');?></legend>
    <?php
        echo $form->input('area_id',array('type'=>'text','length'=>10));
    ?>

    <label for='AreasHazardHazardId'>Hazard</label><select
id='AreasHazardHazardId' name=data[AreasHazard][hazard_id]>
      <?php foreach ($hzds as $h):?>
         <option value=<?php echo $h['Hazard']['id'];?>><?php echo
$h['Hazard']['hazard_name'];?></option>

      <?php endforeach; ?>


          <?php
        echo $form->input(
       'Control',
       array(
               'type' => 'select',
               'multiple' => 'checkbox'
       ),
       $controls
);
    ?>
<?php echo $form->end('Submit');?>

    </fieldset></br>
</div>
<div class="actions">
    <ul>
        <li><?php echo $html->link(__('Back', true),
array('action'=>'index'));?></li>

    </ul>
</div>


//-----//-----//-----//-----//-----//-- index.ctp
---//-----//-----//-----//-----//-----//-----//

<div class="areasHazards index">
<h2><?php __('Checklist View');?></h2>
<p>
<?php
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records out of
%count% total, starting on record %start%, ending on %end%', true)
));
?></p>
<table cellpadding="0" cellspacing="0">
<tr>
    <th><?php echo $paginator->sort('hazard_id');?></th>
    <th><?php echo $paginator->sort('area_id');?></th>
    <th><?php echo $paginator->sort('control_id');?></th>
    <th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($areasHazards as $ah):
    $class = null;
    if ($i++ % 2 == 0) {
        $class = ' class="altrow"';
    }
?>
    <tr<?php echo $class;?>>
        <td>
            <?php echo $ah['Hazard']['hazard_name']; ?>
        </td>
         <td>
            <?php echo $ah['Area']['area_name']; ?>
        </td>

        <td>
            <?php echo $ah['Control']['control_name']; ?>
        </td>
        <td class="actions">
            <?php echo $html->link(__('View', true), array('action'=>'view',
$ah['AreasHazard']['area_id'])); ?>
            <?php echo $html->link(__('Edit', true), array('action'=>'edit',
$ah['AreasHazard']['area_id'])); ?>
            <?php echo $html->link(__('Delete', true),
array('action'=>'delete', $ah['AreasHazard']['area_id']), null,
sprintf(__('Are you sure you want to delete # %s?', true),
$ah['AreasHazard']['area_id'])); ?>
        </td>
    </tr>
<?php endforeach; ?>
</table>
</div>
<div class="paging">
    <?php echo $paginator->prev('<< '.__('previous', true), array(), null,
array('class'=>'disabled'));?>
 |     <?php echo $paginator->numbers();?>
    <?php echo $paginator->next(__('next', true).' >>', array(), null,
array('class'=>'disabled'));?>
</div>




//-----//-----//-----//-----//-----//-- view.ctp
---//-----//-----//-----//-----//-----//-----//

<div class="areasHazards view">
<h2><?php  __('AreasHazard');?></h2>
<dl><?php $i = 0; $class = ' class="altrow"';?>
        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Hazard'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
            <?php echo $areasHazard['Hazard']['hazard_name']; ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Area'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
            <?php echo $areasHazard['Area']['area_name']; ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Control');
?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
            <?php echo $areasHazard['Control']['control_name']; ?>
            &nbsp;
        </dd>



    </dl>
</div>

<div class="actions">
    <ul>


        <li><?php echo $html->link(__('Back', true), array('controller'=>
'areas_hazards', 'action'=>'index')); ?> </li>

    </ul>
</div>






On Tue, Apr 20, 2010 at 4:45 PM, cricket <[email protected]> wrote:

> On Apr 20, 5:40 am, Lady Baleseng <[email protected]> wrote:
> > thank you very much for the multiple checklist.it worked partly.i am
> able to
> > pick the existing hobbies in my system,but now in my view form wen i tick
> > the hobbies that i want added it does not add them,after i click on the
> > submitt button.
> >
> > i also want to be able to edit the checklist at edit form.
>
> What does your controller code look like? Also, what does the
> submitted data look like? Add this:
>
> function add()
> {
>   if (!empty($this->data))
>   {
>      die(debug($this->data));
>
>
> That will display the submitted data array.
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<cake-php%[email protected]>For
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" 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?hl=en

Reply via email to