views:

903

answers:

3

Hi im kinda new in cakephp and having a lot of trouble adjusting.. Here's my biggest problem ..

Im trying to pass a parameter to an action, it does load, but when my script goes from the controller to the view, and goes back to the controller again, its gone.

CONTROLLER CODE

 function add($mac = 0)
{


if(isset($this->params['form']['medico'])) 
{

 $temp= $this->Person->find('first', array('conditions' => array('smartphones_MAC' => $mac)));
 $id= $temp['Person']['id'];

$this->Union->set('events_id', $id+1);
$this->Union->set('people_id', $id);
$this->Union->save();

}

VIEW CODE (This is a menu, i only have one button right now)

 <fieldset>

 <legend>SELECCIONE SU ALERTA</legend>

 <?php 

  echo $form->create('Event'); 

  echo $form->submit('EMERGENCIA MEDICA',array('name'=>'medico')); 

  echo $form->end();

  ?> 

  </fieldset>
A: 

I'm no big fan of using some helpers (like $html) or some methods (like $form's create() and end()). I kinda didn't get your problem, but I think it might be that you have to make a POST request to the same url you are actually into.

<form method="GET" action="<?=$this->here ?>">

Maybe you should give a further explanation of what you are trying to achieve.

metrobalderas
ok , i have a menu with an option, to access this menu i pass one parameter foe example: http://localhost/mobile/events/add/1 , but when i click the menu option, the page refreshes and i get this : http://localhost/mobile/events/add , so the parameter i entered 1 , gets lost, and the script receives a cero which is the default.. basically im trying to Persist the URL parameters..
Ian Cocco
Then that's it. Try using $this->here as the form action.
metrobalderas
A: 

You might want to try using named parameters.

I asked a similar question which you might find helpful:

http://stackoverflow.com/questions/2034343/cakephp-adding-record-with-some-parameters-fixed

Tomba
+2  A: 

When you create the form you don't include the additional url parameters or the fields as inputs. Without either of these the parameters will vanish as they are not part of the new request. You can append additional parameters to the form submission url with

$form->create('Event', array(
    'url' => array('something', 'somethingelse')
));

This will create a form that points at /events/add/something/somethingelse.

Mark Story
thx that totally did it... i had a lot of problems with that.. :D
Ian Cocco
worked.. thx a lot!
Ian Cocco