To pass the lead id the link should be
$html->link('/leads/addactivity/'.$lead['Lead']['id']); // assuming
this is in your view.ctp/thtml
Any values in the url after the controller/action will be passed into
the action as paramerter so urls are in the format
site.com/controller/action/param1/param2/param3 etc
I couldn't find this in the manual just now. Hmmm...
On Jun 14, 7:21 am, Amy1234 <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am trying to build an application. The parent is leads and the
> child association is activity.
>
> everything is linked okay.
>
> when I view a lead I can add a new activity. When I press new activity
> it takes me to the new activity page. How do I get the lead_id that I
> pressedd the new activity link to go automatically and register the
> lead_id in the activity table.
>
> I changed the lead controller to:
>
> <?php
> class LeadsController extends AppController {
>
> var $name = 'Leads';
> var $uses = array('Lead', 'Activity');
> var $helpers = array('Html', 'Form' );
>
> function index() {
> $this->Lead->recursive = 0;
> $this->set('leads', $this->Lead->findAll());
> }
>
> function view($id = null) {
> if(!$id) {
> $this->flash('Invalid id for Lead', '/leads/index');
> }
> $this->set('lead', $this->Lead->read(null, $id));
> }
>
> function add() {
> if(empty($this->data)) {
> $this->set('users',
> $this->Lead->User->generateList());
> $this->Lead->save($this->data);
> $lead_id = $this->Lead->getLastInsertId();
>
> $this->render();
> } else {
> $this->cleanUpFields();
> if($this->Lead->save($this->data)) {
> $this->data['activity']['lead_id'] = $lead_id;
> $this->flash('Lead saved.', '/leads/index');
> } else {
> $this->set('users',
> $this->Lead->User->generateList());
> $this->Lead->Activity->save($this->data);
> }
> }
> }
>
> function edit($id = null) {
> if(empty($this->data)) {
> if(!$id) {
> $this->flash('Invalid id for Lead',
> '/leads/index');
> }
> $this->data = $this->Lead->read(null, $id);
> $this->set('users',
> $this->Lead->User->generateList());
> } else {
> $this->cleanUpFields();
> if($this->Lead->save($this->data)) {
> $this->flash('Lead saved.', '/leads/index');
> } else {
> $this->set('users',
> $this->Lead->User->generateList());
> }
> }
> }
>
> function delete($id = null) {
> if(!$id) {
> $this->flash('Invalid id for Lead', '/leads/index');
> }
> if($this->Lead->del($id)) {
> $this->flash('Lead deleted: id '.$id.'.',
> '/leads/index');
> }
> }
>
> }
>
> function addactivity($lead_id)
> {
> if (!empty($this->data))
>
> {
>
> $this->data['activity']['lead_id'] = $lead_id;
> $this->Lead->Activity->save($this->data);
> }
>
> }
>
> ?>
>
> What else do I need to do to have the lead_id automatically transfer
> to the new activity screen.
>
> Also I would like the lead_id to be inserted via a hidden field.
>
> Thanks
> For your help
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---