I have created a link on my app to allow users to create appointments, but need to pass some extra data across so the app knows which client to book the appointment to. How would I do this?
e.g. <li><?php echo $this->Html->link('Book Appointment', array('admin' => true, 'controller' => 'appointments', 'action' => 'add')); ?></li>
So the url would be something like: /admin/appointments/add?clientid=2
NOTE: If someone thinks this is a bad way to do this please also comment with alternate solutions etc. Thanks
I found this in the documentation: http://book.cakephp.org/view/1442/link
You can do the following:
<li><?php echo $this->Html->link('Book Appointment', array(
'admin' => true,
'controller' => 'appointments',
'action' => 'add',
'?' => array('clientid' => $clientId))
); ?></li>
The code is untested since I don't have CakePHP installed and there was a long time since I used it. I'm sure you can get the example working by looking at the documentation aswell.
You can transfer the id either as a named or unnamed parameter.
Unnamed parameter (the easier way), assuming the id is in $clientId
:
$this->Html->link('Book Appointment', array('admin' => true, 'controller' => 'appointments', 'action' => 'add', $clientId ))
and the url looks like /admin/appointments/add/2
In the controller: function add( $clientId ) { ... }
Named parameter:
$this->Html->link('Book Appointment', array('admin' => true, 'controller' => 'appointments', 'action' => 'add', 'clientId' => $clientId ))
and the url looks like /admin/appointments/add/clientId:2
In the controller: function add() { $clientId = $this->params[ 'named' ][ 'clientId' ]; ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With