Re: Newbie needs help with hidden input helper

2009-03-23 Thread brian

On Mon, Mar 23, 2009 at 9:10 AM, cpeele  wrote:
>
>        function add()
>        {
>                if (!empty($this->data)) {
>
>                        $this->data += array('User' => array('user_id' => 
> $this->Session-
>>read('User.user_id')));
>
>                        if ($this->Event->save($this->data)) {
>
>                                $this->Session->setFlash("A new event has been 
> added");
>                                $this->redirect('/events', null, true);
>                        }
>                }
>        }
> }

$this->data['Event']['user_id'] = $this->Session->read('User.id');

You're setting a foreign key in Event, so it should be in the Event
array and called user_id. But, in the session, you refer to the
User.id, not User.user_id.


>function view($id)
>{
>$events = $this->Event->User->findById($id);
>$this->set('events', $events);
>}

Are you sure you want to do this? I'd think it would be better to pass
the Event ID or date or something else. Although, if you *really* want
to only be able to view an Event based on some User's ID, then just
find based on the foreign key:

'conditions' => array(
  'Event.user_id' => $id
)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Newbie needs help with hidden input helper

2009-03-23 Thread cpeele

Hello again,

I have tried your suggestion but it still does not read the value from
the session. I will paste my entire controller code here.  Thanks
again:

paginate();

if (isset($this->params['requested'])) {
return $events;
}

$this->set('events', $events);
}

function view($id)
{
$events = $this->Event->User->findById($id);
$this->set('events', $events);
}

function add()
{
if (!empty($this->data)) {

$this->data += array('User' => array('user_id' => 
$this->Session-
>read('User.user_id')));

if ($this->Event->save($this->data)) {

$this->Session->setFlash("A new event has been 
added");
$this->redirect('/events', null, true);
}
}
}
}

?>





On Mar 22, 12:44 am, mscdex  wrote:
> On Mar 21, 11:10 pm,cpeele wrote:
>
> > Am I supposed to set something up in order to use $this->Session in my
> > controller?
>
> At the top of your controller, you should only have to ensure your
> $components array attribute includes "Session." For example:
>
> var $components = array('Session');
>
> Then use:
>
> $this->Session->write('User.user_id', $userID);
>
> to write the session variable (replace $userID with the correct user
> ID), and:
>
> $current_userid = $this->Session->read('User.user_id');
>
> to read the current user ID.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Newbie needs help with hidden input helper

2009-03-21 Thread mscdex

On Mar 21, 11:10 pm, cpeele  wrote:
> Am I supposed to set something up in order to use $this->Session in my
> controller?

At the top of your controller, you should only have to ensure your
$components array attribute includes "Session." For example:

var $components = array('Session');

Then use:

$this->Session->write('User.user_id', $userID);

to write the session variable (replace $userID with the correct user
ID), and:

$current_userid = $this->Session->read('User.user_id');

to read the current user ID.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Newbie needs help with hidden input helper

2009-03-21 Thread cpeele

Okay, here's what's going on . I am using $this->Session because
$session in the controller causes it blow up.

$this->data += array('User' => array('user_id' => $this->Session-
>read
('User.user_id')));
$this->Project->saveAll($this->data);

However, now when it saves it doesn't grab the value of user_id stored
in the Session. It should insert the value 1 for the user_id but
instead inserts 0

Am I supposed to set something up in order to use $this->Session in my
controller?

Thanks,

Chris







On Mar 21, 9:12 pm, mscdex  wrote:
> On Mar 21, 9:11 pm, cpeele  wrote:
>
> > Thanks for the help guys. I appreciate it. The reason I need to do
> > this is I need to associate a submitted item (in this case a project)
> > with the logged in user. Is there another way to do this then?
>
> One solution would be to remove the hidden form field and instead
> append a new array containing the user_id to $this->data right before
> you call saveAll:
>
> $this->data += array('User' => array('user_id' => $session->read
> ('User.user_id')));
> $this->Project->saveAll($this->data);
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Newbie needs help with hidden input helper

2009-03-21 Thread cpeele

Actually, can I use the $session helper in a controller? Is it
supposed to be Session ?

Thanks again!

On Mar 21, 9:12 pm, mscdex  wrote:
> On Mar 21, 9:11 pm, cpeele  wrote:
>
> > Thanks for the help guys. I appreciate it. The reason I need to do
> > this is I need to associate a submitted item (in this case a project)
> > with the logged in user. Is there another way to do this then?
>
> One solution would be to remove the hidden form field and instead
> append a new array containing the user_id to $this->data right before
> you call saveAll:
>
> $this->data += array('User' => array('user_id' => $session->read
> ('User.user_id')));
> $this->Project->saveAll($this->data);
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Newbie needs help with hidden input helper

2009-03-21 Thread cpeele

Hey Thanks man! I'll give it a shot!

On Mar 21, 9:12 pm, mscdex  wrote:
> On Mar 21, 9:11 pm, cpeele  wrote:
>
> > Thanks for the help guys. I appreciate it. The reason I need to do
> > this is I need to associate a submitted item (in this case a project)
> > with the logged in user. Is there another way to do this then?
>
> One solution would be to remove the hidden form field and instead
> append a new array containing the user_id to $this->data right before
> you call saveAll:
>
> $this->data += array('User' => array('user_id' => $session->read
> ('User.user_id')));
> $this->Project->saveAll($this->data);
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Newbie needs help with hidden input helper

2009-03-21 Thread mscdex

On Mar 21, 9:11 pm, cpeele  wrote:
> Thanks for the help guys. I appreciate it. The reason I need to do
> this is I need to associate a submitted item (in this case a project)
> with the logged in user. Is there another way to do this then?

One solution would be to remove the hidden form field and instead
append a new array containing the user_id to $this->data right before
you call saveAll:

$this->data += array('User' => array('user_id' => $session->read
('User.user_id')));
$this->Project->saveAll($this->data);
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Newbie needs help with hidden input helper

2009-03-21 Thread cpeele

Thanks for the help guys. I appreciate it. The reason I need to do
this is I need to associate a submitted item (in this case a project)
with the logged in user. Is there another way to do this then?

Thanks again!

Chris

On Mar 21, 4:52 pm, mscdex  wrote:
> I have to agree with John here, you should probably try to keep those
> sorts of things out of user-submittable forms.
>
> Anyhow, the syntax for $form->hidden() is different than you are
> trying to use it as. The second parameter is an $options array, so to
> set a default value use:
>
> echo $form->hidden('fieldname', array( 'value' => 'foo' ));
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Newbie needs help with hidden input helper

2009-03-21 Thread mscdex

I have to agree with John here, you should probably try to keep those
sorts of things out of user-submittable forms.

Anyhow, the syntax for $form->hidden() is different than you are
trying to use it as. The second parameter is an $options array, so to
set a default value use:

echo $form->hidden('fieldname', array( 'value' => 'foo' ));
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Newbie needs help with hidden input helper

2009-03-21 Thread John Andersen

Do not do that! Do not expose your user tables primary key like that
for every to see!

Please explain why you would like to do this?
   John

On Mar 21, 8:39 pm, cpeele  wrote:
> Hey guys,
>
> I have checked the manual and I still find it a little confusing as
> far as how to use the hidden input control.
>
> I have a session variable named User.user_id that I want to put in the
> hidden input helper but can't seem to get it to work.
>
> I have tried the following: echo $form->hidden('user_id', 
> $session->read('User.user_id')); but this does not work. I checked to ensure
>
> that there was indeed something in the session beforehand.
>
> Could someone please help me out with this?
>
> Thank you!
>
> Chris
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Newbie needs help with hidden input helper

2009-03-21 Thread cpeele


Hey guys,

I have checked the manual and I still find it a little confusing as
far as how to use the hidden input control.

I have a session variable named User.user_id that I want to put in the
hidden input helper but can't seem to get it to work.

I have tried the following: echo $form->hidden('user_id', $session-
>read('User.user_id')); but this does not work. I checked to ensure
that there was indeed something in the session beforehand.

Could someone please help me out with this?

Thank you!

Chris


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---