RE: Validate Question

2013-05-10 Thread Advantage+
Right. 
My bad. Good looking out!

 

Thanks guys J

 

From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of André Luis
Sent: Friday, May 10, 2013 8:53 AM
To: cake-php@googlegroups.com
Subject: Re: Validate Question

 

It´s not a rule model have no access to components, you can get it on any
method inside any model using AuthComponent::user('user_id'), that´s why
some components have some static method, an example of this is when you
create a user and need to hash the password before it saves...

 

on model User:

public function beforeSave($options = array()) {

   parent::beforeSave($options);

if(isset($this->data[$this->alias]['password']))
$this->data[$this->alias]['password' ]=
AuthComponent::password($this->data[$this->alias]['password']);

return true;

}

 

This way is recommended by cake book, you can check it here:
http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html
#hashing-passwords

Also you can use SessionComponent::read() if needed...


Em sexta-feira, 10 de maio de 2013 07h54min52s UTC-3, advantage+ escreveu:

If the model has no access to Ssession data from correct MVC structure how
do you validate user_id in the model when saving records?

 

Auth saves the user_id in the session when logged in but if you cannot get
that in the model how do you verify the user_id?

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Validate Question

2013-05-10 Thread André Luis
It´s not a rule model have no access to components, you can get it on any 
method inside any model using AuthComponent::user('user_id'), that´s why 
some components have some static method, an example of this is when you 
create a user and need to hash the password before it saves...

on model User:
public function beforeSave($options = array()) {
   parent::beforeSave($options);
if(isset($this->data[$this->alias]['password'])) 
$this->data[$this->alias]['password' ]= 
AuthComponent::password($this->data[$this->alias]['password']);
return true;
}

This way is recommended by cake book, you can check it here: 
http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#hashing-passwords
Also you can use SessionComponent::read() if needed...

Em sexta-feira, 10 de maio de 2013 07h54min52s UTC-3, advantage+ escreveu:
>
> If the model has no access to Ssession data from correct MVC structure how 
> do you validate user_id in the model when saving records?
>
>  
>
> Auth saves the user_id in the session when logged in but if you cannot get 
> that in the model how do you verify the user_id?
>

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Validate Question

2013-05-10 Thread Chetan Varshney
Create a variable in model
for e.g. in User model
var $auth;

and set this variable value from controller's beforeFilter function
$this->User->auth = $this->Session->read('Auth');

now you can access user id in User model this way

$userId =0;
if(!empty($this->auth['User']['id'])) {
$userId =$this->auth['User']['id'];
}


On Fri, May 10, 2013 at 4:24 PM, Advantage+  wrote:

> If the model has no access to Ssession data from correct MVC structure how
> do you validate user_id in the model when saving records?
>
> ** **
>
> Auth saves the user_id in the session when logged in but if you cannot get
> that in the model how do you verify the user_id?
>
> --
> 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+unsubscr...@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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Chetan Varshney
Ektanjali Softwares Pvt Ltd

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Validate Question

2013-05-10 Thread Advantage+
If the model has no access to Ssession data from correct MVC structure how
do you validate user_id in the model when saving records?

 

Auth saves the user_id in the session when logged in but if you cannot get
that in the model how do you verify the user_id?

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




RE: Validate Question

2010-01-07 Thread Dave
Thanks,

I guess I will just keep what I have, was just curious as to which maybe
better but my guess is the inList function is an array_diff() so its pretty
much the same thing I got going on now

-Original Message-
From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf
Of Miles J
Sent: January-07-10 2:24 PM
To: CakePHP
Subject: Re: Validate Question

You will have to set the validation rule during runtime in your model/
controller, like so:

$this->Model->validate['field']['inList'] = array('rule' => array ('inList',
$myListVariable));

On Jan 7, 2:06 am, John Andersen  wrote:
> Hi Dave,
>
> Is your rule made in accordance with CakePHP custom validation rules?
> If yes, then I don't see a better solution.
>
>
Seehttp://book.cakephp.org/view/150/Custom-Validation-Rules#Adding-your-...
> for the custom validation rules.
>
> Enjoy,
>    John
>
> On Jan 7, 7:48 am, "Dave"  wrote:
>
> > Using the inList validation rule I have 2 questions.
>
> > 'rule' => array('inList', array('0', '1', '2','3', '4', '5', '6', 
> > '7')), will allow values matching 0 thru 7 anything else is invalid
>
> > So my first question is if I created an variable array of values 
> > from a find could i just use 'rule' => array('inList', 
> > $myListVariable),
>
> > and if that is possible how do i get the $myListVariable into the 
> > validation function?
>
> > Or is better to just stick with what im currently doing. For example 
> > I have my country select list and it has a validation 'rule' => 
> > array('checkCountryValues'),
>
> > Model function for the country validation
> > /*
> >  Form Modification Validation
> >  Checks that entered values for Country are Valid
>
> >  */
> >   public function checkCountryValues($data)
> >       {
> >     $valid = false;
> >     $model_table = Inflector::classify($this->useTable);
>
> >     if (!empty($this->data))
> >     {
> >      // this section matches values against database
> >      $value = array($this->data[$model_table]['country_id']);
> >      $results = array_diff($value, $this->Country->find('list', 
> > array('fields' => 'id')));
>
> >      if (empty($results))
>
> >      $valid = true;
> >     }
>
> >   return $valid;
> >       }
>
> > So if anyone messes with the form it returns invalid.
>
> > Ideas?
>
> > Dave

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.725 / Virus Database: 270.14.124/2599 - Release Date: 01/07/10
04:05:00

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: Validate Question

2010-01-07 Thread Miles J
You will have to set the validation rule during runtime in your model/
controller, like so:

$this->Model->validate['field']['inList'] = array('rule' => array
('inList', $myListVariable));

On Jan 7, 2:06 am, John Andersen  wrote:
> Hi Dave,
>
> Is your rule made in accordance with CakePHP custom validation rules?
> If yes, then I don't see a better solution.
>
> Seehttp://book.cakephp.org/view/150/Custom-Validation-Rules#Adding-your-...
> for the custom validation rules.
>
> Enjoy,
>    John
>
> On Jan 7, 7:48 am, "Dave"  wrote:
>
> > Using the inList validation rule I have 2 questions.
>
> > 'rule' => array('inList', array('0', '1', '2','3', '4', '5', '6', '7')),
> > will allow values matching 0 thru 7 anything else is invalid
>
> > So my first question is if I created an variable array of values from a find
> > could i just use 'rule' => array('inList', $myListVariable),
>
> > and if that is possible how do i get the $myListVariable into the validation
> > function?
>
> > Or is better to just stick with what im currently doing. For example I have
> > my country select list and it has a validation 'rule' =>
> > array('checkCountryValues'),
>
> > Model function for the country validation
> > /*
> >  Form Modification Validation
> >  Checks that entered values for Country are Valid
>
> >  */
> >   public function checkCountryValues($data)
> >       {
> >     $valid = false;
> >     $model_table = Inflector::classify($this->useTable);
>
> >     if (!empty($this->data))
> >     {
> >      // this section matches values against database
> >      $value = array($this->data[$model_table]['country_id']);
> >      $results = array_diff($value, $this->Country->find('list',
> > array('fields' => 'id')));
>
> >      if (empty($results))
>
> >      $valid = true;
> >     }
>
> >   return $valid;
> >       }
>
> > So if anyone messes with the form it returns invalid.
>
> > Ideas?
>
> > Dave
Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: Validate Question

2010-01-07 Thread John Andersen
Hi Dave,

Is your rule made in accordance with CakePHP custom validation rules?
If yes, then I don't see a better solution.

See 
http://book.cakephp.org/view/150/Custom-Validation-Rules#Adding-your-own-Validation-Methods-152
for the custom validation rules.

Enjoy,
   John

On Jan 7, 7:48 am, "Dave"  wrote:
> Using the inList validation rule I have 2 questions.
>
> 'rule' => array('inList', array('0', '1', '2','3', '4', '5', '6', '7')),
> will allow values matching 0 thru 7 anything else is invalid
>
> So my first question is if I created an variable array of values from a find
> could i just use 'rule' => array('inList', $myListVariable),
>
> and if that is possible how do i get the $myListVariable into the validation
> function?
>
> Or is better to just stick with what im currently doing. For example I have
> my country select list and it has a validation 'rule' =>
> array('checkCountryValues'),
>
> Model function for the country validation
> /*
>  Form Modification Validation
>  Checks that entered values for Country are Valid
>
>  */
>   public function checkCountryValues($data)
>       {
>     $valid = false;
>     $model_table = Inflector::classify($this->useTable);
>
>     if (!empty($this->data))
>     {
>      // this section matches values against database
>      $value = array($this->data[$model_table]['country_id']);
>      $results = array_diff($value, $this->Country->find('list',
> array('fields' => 'id')));
>
>      if (empty($results))
>
>      $valid = true;
>     }
>
>   return $valid;
>       }
>
> So if anyone messes with the form it returns invalid.
>
> Ideas?
>
> Dave
Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Validate Question

2010-01-06 Thread Dave
Using the inList validation rule I have 2 questions.
 
'rule' => array('inList', array('0', '1', '2','3', '4', '5', '6', '7')),
will allow values matching 0 thru 7 anything else is invalid
 
So my first question is if I created an variable array of values from a find
could i just use 'rule' => array('inList', $myListVariable),
 
and if that is possible how do i get the $myListVariable into the validation
function?
 
Or is better to just stick with what im currently doing. For example I have
my country select list and it has a validation 'rule' =>
array('checkCountryValues'),
 
Model function for the country validation
/*
 Form Modification Validation
 Checks that entered values for Country are Valid
 
 */
  public function checkCountryValues($data)
  {
$valid = false;
$model_table = Inflector::classify($this->useTable);

if (!empty($this->data)) 
{
 // this section matches values against database
 $value = array($this->data[$model_table]['country_id']);
 $results = array_diff($value, $this->Country->find('list',
array('fields' => 'id')));
 
 if (empty($results))
 
 $valid = true;
}
 
  return $valid;
  }

So if anyone messes with the form it returns invalid.

Ideas?
 
Dave

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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