Thursday, June 20, 2013

Re: One page with Search/Edit/Add and Delete Buttons

Im assuming the if() is in your controller not a view file??   


Here is a snip of a view for one of my older apps I am working on updating.  I use postLinks like this

<?php
                            if(count($divisions)>0){
                                foreach ($divisions AS $row){
                                    ?>
                        <tr>
                            <td><?=$row['Divisions']['name'];?></td>
                            <td><?=$row['Divisions']['last_updated'];?></td>
                            <td>
<?php echo $this->Form->postLink('Edit', 
                    array('action' => 'edit', $row['Divisions']['division_id']),
                    array('class'=>'button blue'));?>
<?php echo $this->Form->postLink('Delete', 
                    array('action' => 'delete', $row['Divisions']['division_id']),
                    array('class'=>'button red', 'confirm' => 'Are you sure?'));?>
   </td>
                        </tr>
                                    <?php
                                }
                            } else {
                                ?>
                        <tr>
                            <td colspan="5" style="text-align: center;">No Divisions Configured</td>
                        </tr>
                                <?php
                            }
                        ?>

The delete button would then post to the delete() function in the controller etc

Eric

On Thursday, June 20, 2013 8:04:03 AM UTC-4, Mahdi Miad wrote:
Hi all,
I am new in CakePHP, I developed some applications before and now I need to create my application same as before but with cakePHP, so what I need is one page with add,edit,search and delete button, if I click on search button I need to call search method and edit button with edit method and so on. here is some of my code.
Thanks for your time.

<?php


if (isset($this->request->data['Search'])) { 
    // call Search method with EmployeeID as a primery key

} else if (isset($this->request->data['Add'])) { 
     // call Add method

}else if (isset($this->request->data['Edit'])) { 
    // call Edit method

}else if (isset($this->request->data['Delete'])) { 
    // call Delete method
}



echo $this->Form->create('myModel' );

        echo $this->Form->input('EmployeeID');
        echo $this->Form->input('First Name' );
        echo $this->Form->input('Last Name');
        echo $this->Form->input('Departement');
        echo $this->Form->input('Address'); 
  

        echo $this->Form->submit('Search' , array('name' =>'Search'  ));
        echo $this->Form->submit('Add' , array('name' =>'Add'));
        echo $this->Form->submit('Edit' , array('name' =>'Edit'));
        echo $this->Form->submit('Delete', array('name' =>'Delete'   ));
 

echo $this->form->end();
?>
 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: