Re: Making Paginator first sort direction DESC
In the end my solution was to copy the paginator helper class to my application helpers directory, then in the sort method swap every instance of "asc" and "desc". It's not a great solution, but it works. I'd love to hear about better solutions to get the initial sort direction to be desc instead of asc. On May 8, 12:35 am, Tim W <[EMAIL PROTECTED]> wrote: > Thanks Marcin. > > I don't think i've been entirely clear. I can easily set the sort > order programmatically, but when the user first clicks on a link to > sort a column it automatically sorts ASC. I'd like to change that > behavior to default first to DESC. I can do it by hacking around with > the cake source, or doing it myself, I just wondered if there was a > way built in, since it'd probably be a pretty common thing to try to > do. If not i'll add it and see if I can work out how to submit a > change request. > > Cheers > > Tim > > On May 7, 10:33 pm, "Marcin Domanski" <[EMAIL PROTECTED]> wrote: > > > 'order' => 'Model.column DESC' > > > On Wed, May 7, 2008 at 11:26 AM,TimW<[EMAIL PROTECTED]> wrote: > > > > Thanks for the suggestion, but unfortunately it didn't work for me. > > > > SQL Error: 1054: Unknown column 'DESC' in 'order clause' > > > > I'll spend some time to work this out at some point, i'll post when I > > > do, unless someone's worked it out already and can tell me. > > > > Thanks > > > > Tim > > > > On May 7, 8:11 pm, "Andras Kende" <[EMAIL PROTECTED]> wrote: > > > > Hello, > > > > > try this in your controller: > > > > > var $paginate = array('limit' => 100, 'page' => 1, 'order' => 'DESC'); > > > > > Andras Kende > > > > >http://www.kende.com > > > > > -Original Message- > > > > From: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf > > > > > OfTimW > > > > Sent: Tuesday, May 06, 2008 9:26 AM > > > > To: CakePHP > > > > Subject: Making Paginator first sort direction DESC > > > > > Hi all, > > > > > Paginator's great, like the rest of Cake, but there's one little thing > > > > I haven't been able to work out. By default when you click on a column > > > > to sort it will sort ASC (ascending), but i'd like the first sort to > > > > be DESC (descending). The options suggest this might be possible, but > > > > I haven't worked it out. Does anyone know if this is possible? > > > > > Thanks > > > > >TIm > > > -- > > Marcin Domanskihttp://kabturek.info --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Working 1.2 Auth with "remember me" feature
Here's an updated function to support the good Dr Lecter's idea of resetting the cookie each time the user logs in. I'm fairly sure it works... function loginFromCookie() { $cookie = $this->Cookie->read('Auth.User'); if (!is_null($cookie)) { if ($this->Auth->login($cookie)) { // Clear auth message, just in case we use it. $this->Session->del('Message.auth'); // Write the cookie out again, so the user stays in for another two weeks $this->Cookie->write('Auth.User', $cookie, true, '+2 weeks'); } else { // Delete invalid Cookie $this->Cookie->del('Auth.User'); } } } --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Working 1.2 Auth with "remember me" feature
Good idea resetting the cookie when users log in, I think i'll use that, ta :) On May 13, 11:31 pm, "dr. Hannibal Lecter" <[EMAIL PROTECTED]> wrote: > Here is my implementation in a form of a component: > > http://dsi.vozibrale.com/articles/view/rememberme-component-for-cakephp > > Basically the same functionality as yours (+ the extra "continuous > remembering"), but I don't have a working example with all the views > etc. > > HTH someone too ;-) > > On May 13, 12:42 pm, Tim W <[EMAIL PROTECTED]> wrote: > > > Cake 1.2 Auth is still pretty badly documented, but between a half > > dozen articles I managed to get it all working. None tell the full > > story though, and I don't fully understand it, but I have working code > > I thought i'd share. I may post a bakery article if I get time. For > > now this should help some people. My biggest tip is to get a decent > > IDE and step through the Cake core code if you want to know what's > > going on, I use Komodo, but i'm sure there are others too. Note that I > > don't use groups, as when I first started I couldn't get them working, > > and I don't need them any now. > > > NB: this code was taken from all over the place; I copied, pasted, and > > tweaked. If I could find the original articles i'd credit the authors, > > but they were found all over the place and I didn't save them. My > > apologies to the people I haven't credited. > > > I've removed some of the guff from my own app, so this should work, > > but you might need to tweak minor stuff. > > > Database table > > CREATE TABLE `users` ( > > `id` int(11) NOT NULL auto_increment, > > `username` varchar(40) NOT NULL, > > `password` varchar(60) NOT NULL, > > `state_id` int(11) NOT NULL default '11', > > `email` varchar(40) NOT NULL, > > `created` datetime NOT NULL, > > `modified` datetime NOT NULL, > > PRIMARY KEY (`id`), > > UNIQUE KEY `EMAIL` (`email`), > > UNIQUE KEY `activation_code` (`activation_code`), > > KEY `email_index` (`email`) > > ) > > > *** /views/users/login.ctp (seehttp://www.dynamicdrive.comforthe > > rollover button javascript code, article "OO Dom Image Rollover") > > > User Login > > > > > > Username > > input('username'); ?> > > > > > > Password > > input('password'); ?> > > > > > > Remember Me > > input('remember_me', array('label' => > > 'Remember Me', 'type' => 'checkbox')); ?> > > > > > > > > > $form->submit('/images/login.png', > > array('srcover' => $this->base . '/images/login-over.png', 'srcdown' > > => $this->base . '/images/login-down.png', 'border' => '0'));?> > > > > > > > > > end(); ?> > > > *** /views/users/register.ctp > > > User Registration > > > create('User', array('action' => 'register'));?> > > > > > > > Username > > input('username', > > array_merge($errorMessages, array('size'=>'20', 'div' => null))); > > ?> * > > > > > > > Email Address > > input('email', array_merge($errorMessages, > > array('size'=>'30', 'div' => null))); ?> > class="required_field">* > > Please note your confirmation email will be sent to this address > td> > > > > > > Password > > input('password', array('type'=>'password', > > 'size'=>'15', 'div' => null)); ?> > class="required_field">* > > > > > > Confirm Password > > input('password2', array('type'=>'password', > > 'size'=>'15', 'div' => null)); ?> > class="required_field">* > > > > > > > > submit('/images/register.png', > > array('srcover' => $this->base . '/images/register-over.png', > > 'srcdown&
Working 1.2 Auth with "remember me" feature
Cake 1.2 Auth is still pretty badly documented, but between a half dozen articles I managed to get it all working. None tell the full story though, and I don't fully understand it, but I have working code I thought i'd share. I may post a bakery article if I get time. For now this should help some people. My biggest tip is to get a decent IDE and step through the Cake core code if you want to know what's going on, I use Komodo, but i'm sure there are others too. Note that I don't use groups, as when I first started I couldn't get them working, and I don't need them any now. NB: this code was taken from all over the place; I copied, pasted, and tweaked. If I could find the original articles i'd credit the authors, but they were found all over the place and I didn't save them. My apologies to the people I haven't credited. I've removed some of the guff from my own app, so this should work, but you might need to tweak minor stuff. Database table CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `username` varchar(40) NOT NULL, `password` varchar(60) NOT NULL, `state_id` int(11) NOT NULL default '11', `email` varchar(40) NOT NULL, `created` datetime NOT NULL, `modified` datetime NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `EMAIL` (`email`), UNIQUE KEY `activation_code` (`activation_code`), KEY `email_index` (`email`) ) *** /views/users/login.ctp (see http://www.dynamicdrive.com for the rollover button javascript code, article "OO Dom Image Rollover") User Login Username input('username'); ?> Password input('password'); ?> Remember Me input('remember_me', array('label' => 'Remember Me', 'type' => 'checkbox')); ?> submit('/images/login.png', array('srcover' => $this->base . '/images/login-over.png', 'srcdown' => $this->base . '/images/login-down.png', 'border' => '0'));?> end(); ?> *** /views/users/register.ctp User Registration create('User', array('action' => 'register'));?> Username input('username', array_merge($errorMessages, array('size'=>'20', 'div' => null))); ? > * Email Address input('email', array_merge($errorMessages, array('size'=>'30', 'div' => null))); ?> * Please note your confirmation email will be sent to this address Password input('password', array('type'=>'password', 'size'=>'15', 'div' => null)); ?> * Confirm Password input('password2', array('type'=>'password', 'size'=>'15', 'div' => null)); ?> * submit('/images/register.png', array('srcover' => $this->base . '/images/register-over.png', 'srcdown' => $this->base . '/images/register-down.png', 'border' => '0'));?> end(); ?> *** /controllers/login.php redirect('/home'); } /** * Login the user */ function login() { //-- code inside this function will execute only when autoRedirect was set to false (i.e. in a beforeFilter). if ($this->RequestHandler->isPost()) { if ($this->Auth->user()) { // Does user/password checking if (!empty($this->data) && $this->data['User']['remember_me'] == '1') { // Save cookie only if checkbox ticked $cookie = array(); $cookie['username'] = $this->data['User']['username']; $cookie['password'] = $this->data['User']['password']; $this->Cookie->write('Auth.User', $cookie, true, '+2 weeks'); unset($this->data['User']['remember_me']); } $this->redirect($this->Auth->redirect()); } else { $this->Session->setFlash('Invalid user or password'); } } } /** * Log out user * */ function logout(){ $cookie = $this->Cookie->read('Auth.User'); $this->Cookie->del('Auth.User'); $this->redirect($this->Auth->logout()); } function register() { // Check if user already logged in $i = $this->getUserID(); if ($i != null && $i > 0) { $this->Session->setFlash('You\'re already logged in!'); $this->redirect('/home/index'); } // Setup data for page $this->set('title', $this->appName .'User Registration'); $this->set('errorMessages', array('error' => array('username_size' => 'Your username must be between 3 and 10 characters long', 'password' => 'Your password must be between 4 and 10 characters long', 'email' => 'Please enter a valid email address', 'first_name' => 'name size is too short' ))); if (empty($this->data)) { // Just show the form } else { // Need to encode password2 so it can be matched with password by validation, but need to keep the length // around to check
Re: Accessing views from Cake - problem with array nesting
Thanks for the suggestion Christian. Cake doesn't alias columns, it just lists them inside odd single quotes. I tried aliasing all my columns but it made no difference. Since I have a workaround i'm not going to spend any more time on it. On May 11, 2:05 am, "Christian Winther" <[EMAIL PROTECTED]> wrote: > Just make sure to alias the fields in your SELECT like cake DBO normally does > > SELECT Model.id AS "Model.id" I think - > > Configure::write('debug', 2); > > And check how cake does it :) > > -Original Message- > From: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Tim W > Sent: 10. maj 2008 16:03 > To: CakePHP > Subject: Accessing views from Cake - problem with array nesting > > Hi all, > > I've just spent a hour or so tracking down an issue before realising > it was caused by pointing cake at a view instead of a database table. > In general views work with Cake, but in some seemingly random cases > they fail. > > The problem i've run into was identified and a patch suggested in this > conversation (subject "ake FindAll mysql view occured errors" if the > link doesn't work) > > http://groups.google.com/group/cake-php/browse_thread/thread/e747844d... > > Is there any more recent information or workarounds? I don't like to > change the cake core as it makes upgrading more difficult - i'm on > version 1.2.0.6311 beta. > > Thanks > > Tim --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Accessing views from Cake - problem with array nesting (with workaround or solution)
I probably should have described what causes the error. When I use findAll on the view, with no extra parameters, things work fine. When I add an "order" clause the innermost array loses the name of the model. Without ordering in my findAll call Array ( [0] => Array ( [SampleImageView] => Array ( [id] => 11 [added_by_user_id] => 1 With ordering in my findAll call Array ( [0] => Array ( [0] => Array ( [id] => 11 [added_by_user_id] => 1 Once it's written out like this the problem and solution becomes obvious(my excuse is it's 2am) - change $image['ModelName'] to $image[0] Hope this helps someone out, and maybe someone will work out a patch one day. Cheers Tim On May 11, 2:02 am, Tim W <[EMAIL PROTECTED]> wrote: > Hi all, > > I've just spent a hour or so tracking down an issue before realising > it was caused by pointing cake at a view instead of a database table. > In general views work with Cake, but in some seemingly random cases > they fail. > > The problem i've run into was identified and a patch suggested in this > conversation (subject "ake FindAll mysql view occured errors" if the > link doesn't work) > > http://groups.google.com/group/cake-php/browse_thread/thread/e747844d... > > Is there any more recent information or workarounds? I don't like to > change the cake core as it makes upgrading more difficult - i'm on > version 1.2.0.6311 beta. > > Thanks > > Tim --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Accessing views from Cake - problem with array nesting
Hi all, I've just spent a hour or so tracking down an issue before realising it was caused by pointing cake at a view instead of a database table. In general views work with Cake, but in some seemingly random cases they fail. The problem i've run into was identified and a patch suggested in this conversation (subject "ake FindAll mysql view occured errors" if the link doesn't work) http://groups.google.com/group/cake-php/browse_thread/thread/e747844d9d583bc6/e1e4e6811711f656?lnk=gst&q=findall+mysql+view+join#e1e4e6811711f656 Is there any more recent information or workarounds? I don't like to change the cake core as it makes upgrading more difficult - i'm on version 1.2.0.6311 beta. Thanks Tim --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Making Paginator first sort direction DESC
Thanks Marcin. I don't think i've been entirely clear. I can easily set the sort order programmatically, but when the user first clicks on a link to sort a column it automatically sorts ASC. I'd like to change that behavior to default first to DESC. I can do it by hacking around with the cake source, or doing it myself, I just wondered if there was a way built in, since it'd probably be a pretty common thing to try to do. If not i'll add it and see if I can work out how to submit a change request. Cheers Tim On May 7, 10:33 pm, "Marcin Domanski" <[EMAIL PROTECTED]> wrote: > 'order' => 'Model.column DESC' > > > > On Wed, May 7, 2008 at 11:26 AM, Tim W <[EMAIL PROTECTED]> wrote: > > > Thanks for the suggestion, but unfortunately it didn't work for me. > > > SQL Error: 1054: Unknown column 'DESC' in 'order clause' > > > I'll spend some time to work this out at some point, i'll post when I > > do, unless someone's worked it out already and can tell me. > > > Thanks > > > Tim > > > On May 7, 8:11 pm, "Andras Kende" <[EMAIL PROTECTED]> wrote: > > > Hello, > > > > try this in your controller: > > > > var $paginate = array('limit' => 100, 'page' => 1, 'order' => 'DESC'); > > > > Andras Kende > > > >http://www.kende.com > > > > -Original Message- > > > From: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf > > > > Of Tim W > > > Sent: Tuesday, May 06, 2008 9:26 AM > > > To: CakePHP > > > Subject: Making Paginator first sort direction DESC > > > > Hi all, > > > > Paginator's great, like the rest of Cake, but there's one little thing > > > I haven't been able to work out. By default when you click on a column > > > to sort it will sort ASC (ascending), but i'd like the first sort to > > > be DESC (descending). The options suggest this might be possible, but > > > I haven't worked it out. Does anyone know if this is possible? > > > > Thanks > > > > TIm > > -- > Marcin Domanskihttp://kabturek.info --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Making Paginator first sort direction DESC
Thanks for the suggestion, but unfortunately it didn't work for me. SQL Error: 1054: Unknown column 'DESC' in 'order clause' I'll spend some time to work this out at some point, i'll post when I do, unless someone's worked it out already and can tell me. Thanks Tim On May 7, 8:11 pm, "Andras Kende" <[EMAIL PROTECTED]> wrote: > Hello, > > try this in your controller: > > var $paginate = array('limit' => 100, 'page' => 1, 'order' => 'DESC'); > > Andras Kende > > http://www.kende.com > > -Original Message- > From: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf > > Of Tim W > Sent: Tuesday, May 06, 2008 9:26 AM > To: CakePHP > Subject: Making Paginator first sort direction DESC > > Hi all, > > Paginator's great, like the rest of Cake, but there's one little thing > I haven't been able to work out. By default when you click on a column > to sort it will sort ASC (ascending), but i'd like the first sort to > be DESC (descending). The options suggest this might be possible, but > I haven't worked it out. Does anyone know if this is possible? > > Thanks > > TIm --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Making Paginator first sort direction DESC
Hi all, Paginator's great, like the rest of Cake, but there's one little thing I haven't been able to work out. By default when you click on a column to sort it will sort ASC (ascending), but i'd like the first sort to be DESC (descending). The options suggest this might be possible, but I haven't worked it out. Does anyone know if this is possible? Thanks TIm --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: 1.2 validation - may be blank, but if filled in must be a decimal
Ah that's even better, thank you grrigri, you've made my life a little easier :-) Tim On Mar 28, 10:40 pm, grigri <[EMAIL PROTECTED]> wrote: > All validation entries have an `allowEmpty` parameter that says > whether the field must be filled in or not. An empty field will *not* > go through the validation rule itself and will be validated or failed > depending on the `allowEmpty` parameter (not to be confused with the > `required` parameter, which controls whether the field must be > *present* in the data). > > To validate a decimal number you can use a callback, like you have, or > a regular expression. For example: > > var $validate = array( > 'field' => array( > 'allowEmpty' => true, > 'rule' => '/^[0-9]*\\.?[0-9]+$/', > 'message' => 'This must be blank or a positive decimal number' > ) > ); > > You could use a different regular expression to allow negative > numbers, enforce limits on the fraction digits, or allow scientific > notation as well. > > For example, if you wanted a positive number with maximum 2 digits > after the decimal point then you'd use something like: > > '/^[0-9]+(\\.[0-9]{,2})?$/' > > On Mar 28, 8:12 am, Tim W <[EMAIL PROTECTED]> wrote: > > > In case anyone else wants to know how i've done it, it's as simple as > > this > > > Model > > > var $validate = array( > > 'fieldName' => array('integer_optional' => array('rule' => > > array('optionalInteger', 'fieldName'))) > > ); > > // NB: integer_optional is the key to look up the error message > > > function optionalInteger($data, $fieldName) { > > if (strlen($data[$fieldName]) > 0) { > > return is_numeric($data); > > } > > > return true; > > > } > > > I couldn't work out how to call an existing validation method (given > > the 2 minutes I spent on it) so I just wrote my own since it was > > trivial and quicker. I'm still interested to hear a better way to do > > this, if one exists :) > > > Tim > > > On Mar 28, 8:56 pm, Tim W <[EMAIL PROTECTED]> wrote: > > > > Hi all, > > > > I have some data that's optional, but if it's filled in it must be a > > > decimal. Is there an easy way to do this with 1.2 validation? My > > > current though is that I might create a custom validation rule, and > > > from their if the field isn't blank then send it through to the built > > > in validation code. > > > > Thanks > > > > Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: 1.2 custom validation methods for multiple fields
I've worked this one out myself - and it was pretty obvious: use a beforeValidate method. I've included one below in case anyone else searches and needs the answer /** * Returns true if all is ok, false if something failed validation */ function beforeValidate() { echo ''; // Sample code to invalidate one field and make validation fail $this->invalidate('field_Name', 'messageKey'); // messageKey can be the error message or the key to the error message in the messages array (see 1.2 validation documentation) return false; } On Mar 28, 9:18 pm, Tim W <[EMAIL PROTECTED]> wrote: > Hi all, > > Say I have a check box and a text field on a form. If the check box is > checked the form has to have a number in it. If the check box isn't > checked then it must be empty. Does anyone know how to do this > validation in 1.2? I could write a custom validation method but I > can't work out how to access multiple pieces of data from the method. > > Thanks > > Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
1.2 custom validation methods for multiple fields
Hi all, Say I have a check box and a text field on a form. If the check box is checked the form has to have a number in it. If the check box isn't checked then it must be empty. Does anyone know how to do this validation in 1.2? I could write a custom validation method but I can't work out how to access multiple pieces of data from the method. Thanks Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: 1.2 validation - may be blank, but if filled in must be a decimal
In case anyone else wants to know how i've done it, it's as simple as this Model var $validate = array( 'fieldName' => array('integer_optional' => array('rule' => array('optionalInteger', 'fieldName'))) ); // NB: integer_optional is the key to look up the error message function optionalInteger($data, $fieldName) { if (strlen($data[$fieldName]) > 0) { return is_numeric($data); } return true; } I couldn't work out how to call an existing validation method (given the 2 minutes I spent on it) so I just wrote my own since it was trivial and quicker. I'm still interested to hear a better way to do this, if one exists :) Tim On Mar 28, 8:56 pm, Tim W <[EMAIL PROTECTED]> wrote: > Hi all, > > I have some data that's optional, but if it's filled in it must be a > decimal. Is there an easy way to do this with 1.2 validation? My > current though is that I might create a custom validation rule, and > from their if the field isn't blank then send it through to the built > in validation code. > > Thanks > > Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
1.2 validation - may be blank, but if filled in must be a decimal
Hi all, I have some data that's optional, but if it's filled in it must be a decimal. Is there an easy way to do this with 1.2 validation? My current though is that I might create a custom validation rule, and from their if the field isn't blank then send it through to the built in validation code. Thanks Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Cake core code infinite loop/recursive rendering issue
Hi all, I have an issue with rendering getting itself into an infinite loop. I've stepped through the code I can see what's going on, but I don't want to mess with the core given I don't have a good overview of how it all fits together. I can consistently reproduce this problem by doing one thing in my app - a post that adds a row to a database table. The odd thing is when I clear the CAKEPHP cookie the issue goes away - as well as logging me out of my app (i'm using Auth). Starting at Controller->render Cake renders the view, then it hits line 347 of view.php (code below) and it skips through a bit more code back to the start of Controller->render to render the layout. While rendering the layout it gets back to that same line and again jumps back to Controller->render to render the layout again - I can confirm this is what I see in my web browser. The problem is it doesn't seem to know it's rendering the layout, and it gets into a recursive loop. One solution might be some kind of a flag to say "hey i'm rendering the layout already, don't do it again", but it would probably be better to work out why it does it than just adding a flag. if ($layout && $this->autoLayout) { // view.php line 347 $out = $this->renderLayout($out, $layout); I'm using Cake 1.2.0.6311-beta on Windows XP with the WAMP stack (PHP 5.2.5, mySql 5.0.45, Apache 2.2.6). Any thoughts or help would be appreciated! Tim Here's what I see in my web browser. ( ! ) Fatal error: Maximum function nesting level of '100' reached, aborting! in D:\Common\ApacheDocroot\cake\libs\debugger.php on line 143 Call Stack # TimeFunctionLocation 1 1.1219 {main}( ) ..\index.php:0 2 2.1623 Dispatcher->dispatch( ???, ??? )..\index.php:84 3 3.0177 Dispatcher->_invoke( ???, ???, ??? )..\dispatcher.php:240 ** First infine loop iteration starts here ** 4 3.0178 Controller->render( ???, ???, ??? ) ..\dispatcher.php:272 5 3.0156 View->render( ???, ???, ??? ) ..\controller.php:712 6 3.0992 View->renderLayout( ???, ??? ) ..\view.php:348 7 3.1013 View->_render( ???, ???, ???, ??? ) ..\view.php:448 8 3.1038 include( 'D:\Common\ApacheDocroot\testsite\views\layouts \default.ctp' ) ..\view.php:648 9 3.1047 SessionHelper->flash( ??? ) ..\default.ctp:73 10 3.1054 View->renderLayout( ???, ??? ) ..\session.php:143 11 3.1054 View->_getLayoutFileName( ??? ) ..\view.php:416 12 3.1236 View->_missingView( ???, ??? ) ..\view.php:839 13 3.1273 Object->cakeError( ???, ??? ) ..\view.php:873 14 3.1344 ErrorHandler->__construct( ???, ??? ) ..\object.php:169 15 3.1403 call_user_func_array ( ???, ??? ) ..\error.php:90 16 3.1403 ErrorHandler->missingLayout( ??? ) ..\error.php:0 ** Second iteration starts here ** 17 3.1409 Controller->render( ???, ???, ??? ) ..\error.php:269 18 3.1414 View->render( ???, ???, ??? ) ..\controller.php:712 19 3.1555 View->renderLayout( ???, ??? ) ..\view.php:348 20 3.1406 View->_render( ???, ???, ???, ??? ) ..\view.php:448 21 3.1406 include( 'D:\Common\ApacheDocroot\testsite\views\layouts \default.ctp' ) ..\view.php:648 22 3.1406 SessionHelper->flash( ??? ) ..\default.ctp:73 23 3.1406 View->renderLayout( ???, ??? ) ..\session.php:143 24 3.1406 View->_getLayoutFileName( ??? ) ..\view.php:416 25 3.1570 View->_missingView( ???, ??? ) ..\view.php:839 26 3.1605 Object->cakeError( ???, ??? ) ..\view.php:873 27 3.1605 ErrorHandler->__construct( ???, ??? ) ..\object.php:169 28 3.1613 call_user_func_array ( ???, ??? ) ..\error.php:90 29 3.1613 ErrorHandler->missingLayout( ??? ) ..\error.php:0 ** Continues in this loop until shut down ** --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Auth 1.2 - login only if user state = activated?
I just tried it and it works perfectly, thank you Grigri. And wow, quick replies! :) On Feb 15, 11:51 pm, grigri <[EMAIL PROTECTED]> wrote: > Just set $this->Auth->userScope = array('User.state_id' => WHATEVER); > in your controller's beforeFilter callback. > > On Feb 15, 10:43 am, Tim W <[EMAIL PROTECTED]> wrote: > > > Hi all, > > > My user table/model has a state_id field. I'd like to configure Auth > > so that it only lets people login is the state is a certain value. Is > > there an easy way to do this? > > > Two lines in auth.php suggest it should be possible > > > 38: $conditions = $this->userScope; // (previously $conditions is a > > null parameter) > > 77: $data = $model->find(array_merge($find, $conditions), null, null, > > -1); > > > If I could work out how to pass a condition in that would do the job. > > Has anyone done it? > > > Thanks > > > Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Auth 1.2 - login only if user state = activated?
That sound easy, i'll give it ago, thanks Grigri :) On Feb 15, 11:51 pm, grigri <[EMAIL PROTECTED]> wrote: > Just set $this->Auth->userScope = array('User.state_id' => WHATEVER); > in your controller's beforeFilter callback. > > On Feb 15, 10:43 am, Tim W <[EMAIL PROTECTED]> wrote: > > > Hi all, > > > My user table/model has a state_id field. I'd like to configure Auth > > so that it only lets people login is the state is a certain value. Is > > there an easy way to do this? > > > Two lines in auth.php suggest it should be possible > > > 38: $conditions = $this->userScope; // (previously $conditions is a > > null parameter) > > 77: $data = $model->find(array_merge($find, $conditions), null, null, > > -1); > > > If I could work out how to pass a condition in that would do the job. > > Has anyone done it? > > > Thanks > > > Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Auth 1.2 - login only if user state = activated?
Thanks Dardo. I'm still a beginner at Auth, i'd really appreciate a line of code and a suggestion where it should go. The login() method of my UserController is never called during the login process, execution jumps straight to the login method in auth.php. On Feb 15, 11:48 pm, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote: > Use AuthComponent::$userScope = array() // accepts conditions in the > same way that Model::findAll() > > On Fri, Feb 15, 2008 at 8:43 AM, Tim W <[EMAIL PROTECTED]> wrote: > > > Hi all, > > > My user table/model has a state_id field. I'd like to configure Auth > > so that it only lets people login is the state is a certain value. Is > > there an easy way to do this? > > > Two lines in auth.php suggest it should be possible > > > 38: $conditions = $this->userScope; // (previously $conditions is a > > null parameter) > > 77: $data = $model->find(array_merge($find, $conditions), null, null, > > -1); > > > If I could work out how to pass a condition in that would do the job. > > Has anyone done it? > > > Thanks > > > Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Auth 1.2 - login only if user state = activated?
Hi all, My user table/model has a state_id field. I'd like to configure Auth so that it only lets people login is the state is a certain value. Is there an easy way to do this? Two lines in auth.php suggest it should be possible 38: $conditions = $this->userScope; // (previously $conditions is a null parameter) 77: $data = $model->find(array_merge($find, $conditions), null, null, -1); If I could work out how to pass a condition in that would do the job. Has anyone done it? Thanks Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: AppModel retaining previous insert ID
Thanks Samuel, I didn't think to check if there was a create type method, cheers :) On Feb 7, 3:00 pm, "Samuel DeVore" <[EMAIL PROTECTED]> wrote: > I usually use $this->ModelName->create(); > > On Feb 6, 2008 5:50 PM, Tim W <[EMAIL PROTECTED]> wrote: > > > > > > > Hi all, > > > I've got a piece of code that does an insert, then and update of the > > previous row inserted, then the code loops around and does the same > > thing again for a different data set. I've found an issue that the > > second time around the loop the AppModel is retaining the ID of the > > previous insert and so is doing an update instead of an insert. After > > stepping into the model.php source eventually found that it was > > getting an ID from "$this->contr->ModelName->id" that was saved on the > > previous insert. > > > Adding "$this->contr->ModelName->id = null" fixed the issue, and made > > the model do an insert instead of an update. This feels like a hack > > though, and I don't like hacks, they often come back to bite you > > later. > > > Does anyone know why the model's retaining this ID value, and why it's > > picking it up from the previous insert when it's missing from the > > array of data I tell it to save? > > > Thanks > > > Tim > > -- > -- > (the old fart) the advice is free, the lack of crankiness will cost you > > - its a fine line between a real question and an idiot > > http://blog.samdevore.com/archives/2007/03/05/when-open-source-bugs-me/http://blog.samdevore.com/cakephp-pages/my-cake-wont-bake/http://blog.samdevore.com/cakephp-pages/i-cant-bake/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
AppModel retaining previous insert ID
Hi all, I've got a piece of code that does an insert, then and update of the previous row inserted, then the code loops around and does the same thing again for a different data set. I've found an issue that the second time around the loop the AppModel is retaining the ID of the previous insert and so is doing an update instead of an insert. After stepping into the model.php source eventually found that it was getting an ID from "$this->contr->ModelName->id" that was saved on the previous insert. Adding "$this->contr->ModelName->id = null" fixed the issue, and made the model do an insert instead of an update. This feels like a hack though, and I don't like hacks, they often come back to bite you later. Does anyone know why the model's retaining this ID value, and why it's picking it up from the previous insert when it's missing from the array of data I tell it to save? Thanks Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Cake 1.2 Auth component redirecting to a weird path
I'm sorry you've gone past what I know, sorry I couldn't be of more help. I've found having a good debugger really, really helps track down issues. Good luck! On Feb 6, 10:58 am, Arne-Kolja Bachstein <[EMAIL PROTECTED]> wrote: > Hi Tim, > > I added it, but it doesnt change anything. Anyway, how is the > loginRedirect handled usually? Is it, like I assume, $this- > > >redirect($this->Auth->loginRedirect()) within my login method? > > Arne > > On 5 Feb., 22:52, Tim W <[EMAIL PROTECTED]> wrote: > > > The only thing that comes to mind is that you're missing a line I have > > in my beforeFilter action, your might need something like this > > > $this->Auth->loginAction = array('controller' => 'users', 'action' => > > 'login'); > > > If that doesn't work you'll have me stumped, someone with more than 2 > > days experience with auth might have to help! > > > On Feb 6, 10:48 am, Arne-Kolja Bachstein <[EMAIL PROTECTED]> wrote: > > > > Hi Tim, > > > > here it is: > > > > --- > > > function beforeFilter() > > > { > > > Security::setHash('md5'); > > > $this->Auth->authorize = 'controller'; > > > $this->Auth->logoutRedirect = '/'; > > > $this->Auth->loginRedirect = array('controller' => > > > 'pages', 'action' > > > => 'home'); // already tried to set this to another location > > > $this->Auth->loginError = 'Die eingegebenen Daten sind > > > ungültig. > > > Bitte überprüfen Sie ggfs. die Schreibweise.'; > > > > if ($this->isAuthorized()) > > > { > > > if ($this->Session->read('authenticated') != 1) > > > { > > > $this->prepareUser($this->Auth->user()); > > > } > > > > $this->set('user', $this->Session->read('user')); > > > $this->set('authenticated', > > > $this->Session->read('authenticated')); > > > $this->set('profiles_menuitems', > > > $this->Session->read('profiles_menuitems')); > > > > $this->set('is_admin', $this->isAdmin()); > > > > $this->prepareSubmenu(); > > > } > > > else > > > { > > > $this->Session->delete('user'); > > > $this->Session->delete('authenticated'); > > > $this->Session->delete('profiles_menuitems'); > > > } > > > } > > > --- > > > > Best regards > > > > Arne > > > > On 5 Feb., 22:07, Tim W <[EMAIL PROTECTED]> wrote: > > > > > Can you post your AppController beforeFilter method? > > > > > On Feb 6, 9:55 am, Arne-Kolja Bachstein <[EMAIL PROTECTED]> wrote: > > > > > > Hi there, > > > > > > I've got a slight problem with my Auth component atm. It always > > > > > redirects me to a specific but really weird URL when successfully > > > > > logging in. The URL is the path to one of the images used by Thickbox > > > > > (a jQuery script), so it results in the following: > > > > > > --- > > > > > Missing Method in UsersController > > > > > Error: The action images is not defined in controller UsersController > > > > > Error: Create UsersController::images() in file: app/controllers/ > > > > > users_controller.php. > > > > > > > > > class UsersController extends AppController { > > > > > var $name = 'Users'; > > > > > function images() { > > > > > }} > > > > > > ?> > > > > > Notice: If you want to customize this error message, create app/views/ > > > > > errors/missing_action.ctp. > > > > > --- > > > > > > The URL that's called is always the same: /users/images/ > > > > > loadingAnimation.gif > > > > > > I cannot explain this behavior, as the whole site doesnt contain any > > > > > link to this file except directly from the JS file that's included > > > > > using $javascript->link(). > > > > > > It also doesnt matter where I am trying to connect a redirect call. Be > > > > > it from within /users/login or by setting $this->Auth->loginRedirect, > > > > > it always results in my redirect being overriden and the user > > > > > redirected to the image path. > > > > > > Does anyone know something about this problem? > > > > > > Best regards > > > > > > Arne --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Cake 1.2 Auth component redirecting to a weird path
The only thing that comes to mind is that you're missing a line I have in my beforeFilter action, your might need something like this $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login'); If that doesn't work you'll have me stumped, someone with more than 2 days experience with auth might have to help! On Feb 6, 10:48 am, Arne-Kolja Bachstein <[EMAIL PROTECTED]> wrote: > Hi Tim, > > here it is: > > --- > function beforeFilter() > { > Security::setHash('md5'); > $this->Auth->authorize = 'controller'; > $this->Auth->logoutRedirect = '/'; > $this->Auth->loginRedirect = array('controller' => 'pages', > 'action' > => 'home'); // already tried to set this to another location > $this->Auth->loginError = 'Die eingegebenen Daten sind > ungültig. > Bitte überprüfen Sie ggfs. die Schreibweise.'; > > if ($this->isAuthorized()) > { > if ($this->Session->read('authenticated') != 1) > { > $this->prepareUser($this->Auth->user()); > } > > $this->set('user', $this->Session->read('user')); > $this->set('authenticated', > $this->Session->read('authenticated')); > $this->set('profiles_menuitems', > $this->Session->read('profiles_menuitems')); > > $this->set('is_admin', $this->isAdmin()); > > $this->prepareSubmenu(); > } > else > { > $this->Session->delete('user'); > $this->Session->delete('authenticated'); > $this->Session->delete('profiles_menuitems'); > } > } > --- > > Best regards > > Arne > > On 5 Feb., 22:07, Tim W <[EMAIL PROTECTED]> wrote: > > > Can you post your AppController beforeFilter method? > > > On Feb 6, 9:55 am, Arne-Kolja Bachstein <[EMAIL PROTECTED]> wrote: > > > > Hi there, > > > > I've got a slight problem with my Auth component atm. It always > > > redirects me to a specific but really weird URL when successfully > > > logging in. The URL is the path to one of the images used by Thickbox > > > (a jQuery script), so it results in the following: > > > > --- > > > Missing Method in UsersController > > > Error: The action images is not defined in controller UsersController > > > Error: Create UsersController::images() in file: app/controllers/ > > > users_controller.php. > > > > > class UsersController extends AppController { > > > var $name = 'Users'; > > > function images() { > > > }} > > > > ?> > > > Notice: If you want to customize this error message, create app/views/ > > > errors/missing_action.ctp. > > > --- > > > > The URL that's called is always the same: /users/images/ > > > loadingAnimation.gif > > > > I cannot explain this behavior, as the whole site doesnt contain any > > > link to this file except directly from the JS file that's included > > > using $javascript->link(). > > > > It also doesnt matter where I am trying to connect a redirect call. Be > > > it from within /users/login or by setting $this->Auth->loginRedirect, > > > it always results in my redirect being overriden and the user > > > redirected to the image path. > > > > Does anyone know something about this problem? > > > > Best regards > > > > Arne --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: menu and css problem with path
Can you post the exact source code that generates the section in question, as well as the code generated by Cake? In your web browser you'll have to choose "view source" and copy and paste it out. On Feb 6, 10:26 am, redcom <[EMAIL PROTECTED]> wrote: > hello > i have the following problem. > i have created a default layout. > i put there a menu: > > > status/general General Status > status/detail Detailed Status > > > if i click on the general status and then on the detail status link i will > get redirected to something like: > status/general/status/detail > > and vice versa. > > how can i solve this problem? > > i really do now know how to put the correct path for the menu and also for > the css: > > i use a general css file for the layout but since every path is changed > based on the request i sould have a css file in every directory. > > is there a problem with the mod_rewrite since the status is the controller > and the general/details are the methods? > > Thanks in advance. > I am a novice in the cakephp and please point me in the write direction. > since i didn't found the answer in the manual. > -- > View this message in > context:http://www.nabble.com/menu-and-css-problem-with-path-tp15241839p15241... > Sent from the CakePHP mailing list archive at Nabble.com. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Cake 1.2 Auth component redirecting to a weird path
Can you post your AppController beforeFilter method? On Feb 6, 9:55 am, Arne-Kolja Bachstein <[EMAIL PROTECTED]> wrote: > Hi there, > > I've got a slight problem with my Auth component atm. It always > redirects me to a specific but really weird URL when successfully > logging in. The URL is the path to one of the images used by Thickbox > (a jQuery script), so it results in the following: > > --- > Missing Method in UsersController > Error: The action images is not defined in controller UsersController > Error: Create UsersController::images() in file: app/controllers/ > users_controller.php. > class UsersController extends AppController { > var $name = 'Users'; > function images() { > }} > > ?> > Notice: If you want to customize this error message, create app/views/ > errors/missing_action.ctp. > --- > > The URL that's called is always the same: /users/images/ > loadingAnimation.gif > > I cannot explain this behavior, as the whole site doesnt contain any > link to this file except directly from the JS file that's included > using $javascript->link(). > > It also doesnt matter where I am trying to connect a redirect call. Be > it from within /users/login or by setting $this->Auth->loginRedirect, > it always results in my redirect being overriden and the user > redirected to the image path. > > Does anyone know something about this problem? > > Best regards > > Arne --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Controller without model/table possible?
Hi all, Is it possible to have a controller that doesn't map directly to a model or database table? I want an admin section for my website where I can edit users and other models, it'll hook into existing models rather than having its own. Thanks Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Auth in 1.2 - get current user?
Do you have sample vode for those Andy? I've also been banging my head against 1.2 Auth for about 3 days and i'm tempted to rip it out and write my own - which I expect to take about 2 hours. On Feb 5, 11:08 pm, AD7six <[EMAIL PROTECTED]> wrote: > > 2. When refresh a exprired auth page , it'll jump to login page. But > > how can go back to the same page after relogin > > In your login function add this sort of logic: > > if ( the referer isn't in the session) { > put it in the session > > } > > In your app controller before filter tell the auth component to > redirect after login to the location you put in the session > > hth, > > AD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Auth in 1.2 - get current user?
Thanks Amit. I think i've cracked auth in 1.2 and the "remember me" cookie issue. I'll go try and work out ACL now, if I can i'll put a fully working sample project up somewhere. On Feb 5, 12:59 am, "Amit Badkas" <[EMAIL PROTECTED]> wrote: > On Feb 4, 2008 5:13 PM, Tim W <[EMAIL PROTECTED]> wrote: > > > > > Hi all, > > > Thanks mostly to the tutorial linked below I have basic auth working > > in my project. I can create a user in the database (that took a while > > to figure out), have users view public content without logging in, and > > make users log in before they go to a page that's for registered only. > > So far I haven't figured out quite how it works, but it seems to. What > > i'm trying to do is show the "edit" link on a webpage only to > > administrators. > > > I have a few questions, the first being by far the most important: > > 1) How do I get the username and group (or just the user object) of > > the user currently logged in? I've looked at everything in my debugger > > and can't spot the information anywhere. > > - If you are using CakePHP-1.2's built-in Auth component then, in controller > then use $this->Auth->user() to get all user data or > $this->Auth->user('field_name') to get that field's value and if you are in > view then use $session->read('Auth.UserModelName') to get all user data > (change the UserModelName to your need) or $session->read(' > Auth.UserModelName.field_name') to get particular field's value > > -- > Regards, > Amit > > http://amitrb.wordpress.com/http://coppermine-gallery.net/http://cheesecake-photoblog.org/http://www.sanisoft.com/blog/author/amitbadkas --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Auth in 1.2 - get current user?
Hi all, Thanks mostly to the tutorial linked below I have basic auth working in my project. I can create a user in the database (that took a while to figure out), have users view public content without logging in, and make users log in before they go to a page that's for registered only. So far I haven't figured out quite how it works, but it seems to. What i'm trying to do is show the "edit" link on a webpage only to administrators. I have a few questions, the first being by far the most important: 1) How do I get the username and group (or just the user object) of the user currently logged in? I've looked at everything in my debugger and can't spot the information anywhere. 2) Is there an easy way to get the user role or group from the view? ie I only want to show the "go to administration" link if the user's an admin. 3) How does ACL relate to what i've done? Once I get a basic auth system up and running I hope to put together a sample project so people can download it, throw it into their project, and have it work complete with login, registration page, user models, etc. The most useful tutorial i've found: http://www.webdevelopment2.com/cakephp-auth-component-tutorial-1/ adn http://www.webdevelopment2.com/cakephp-auth-component-tutorial-2/ Other i've looked at are below http://www.littlehart.net/atthekeyboard/2007/09/11/a-hopefully-useful-tutorial-for-using-cakephps-auth-component/ http://www.littlehart.net/atthekeyboard/2007/11/20/follow-up-to-a-hopefully-usefull-tutorial-for-using-cakephps-auth-component/ http://lemoncake.wordpress.com/2007/07/15/using-aclbehavior-in-cakephp-12/ http://lemoncake.wordpress.com/2007/07/19/using-authcomponent-and-acl-in-cakephp-12/ Thanks Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: HABTM - read only associations in Cake 1.2
Thanks for your thoughts Adam. I made a very simple function (below), the result seems to be that even if there isn't a LensMount entry Cake still deletes the old HABTM table record, and tries to recreate it. I think the only way I can do this is to stop using the HABTM relationship and do it manually - in this case it's not hard to do. $j = $this->Lens->findById(1); $j['Lens']['name'] = 'x' . $j['Lens']['name']; $j['Lens'][0] = null; $this->Lens->save($j['Lens'])) Other ideas are welcome Thanks Tim On Feb 2, 12:01 pm, Adam Royle <[EMAIL PROTECTED]> wrote: > I may be wrong in saying this, but I don't thinkcakeshould affect > yourHABTMassociationsif there is no LensMount key in $this->data > when you save. > > Try pr($this->data); before your save to see what keys are sent to the > model. > > Adam > > On Feb 2, 6:55 am, Tim Wild <[EMAIL PROTECTED]> wrote: > > > Does anyone have an idea about this? Or do I stop usingHABTMand do it > > with a plain old database call? > > > Tim W wrote: > > > Hi all, > > > > I have aHABTMrelationship that's working, but I want to tell it not > > > to delete and create new rows in the many to many table - Ionlywant > > > it to treat that table asreadonly. Using the following unbindModel > > > command doesn't seem to affect it. > > > > $this->Lens->unbindModel(array('hasAndBelongsToMany' => > > > array('LensMount'))); > > > > (Just FYI the models are Lens and LensMount, with appropriate tables, > > > and a lenses_lens_mounts table with no model) > > > > I've seen the links posted to "Working withHABTMassociations" and > > > "HABTMAdd & Delete Behavior", but neither seem to address my problem. > > > I figure there must be a simple way to disable theHABTMduring save. > > > > How do I tellCakenot to mess with the join table? > > > > Thanks > > > > Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
HABTM - read only associations in Cake 1.2
Hi all, I have a HABTM relationship that's working, but I want to tell it not to delete and create new rows in the many to many table - I only want it to treat that table as read only. Using the following unbindModel command doesn't seem to affect it. $this->Lens->unbindModel(array('hasAndBelongsToMany' => array('LensMount'))); (Just FYI the models are Lens and LensMount, with appropriate tables, and a lenses_lens_mounts table with no model) I've seen the links posted to "Working with HABTM associations" and "HABTM Add & Delete Behavior", but neither seem to address my problem. I figure there must be a simple way to disable the HABTM during save. How do I tell Cake not to mess with the join table? Thanks Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Saving model without saving associated models
Hi all, I'm doing a save of a model, it has an association and the key is being used in a join during the update, so that field isn't being saved. I need to disable the join for the save so I can update the field. Can anyone tell me how to do this? I think I can do this using the unbindModel() method, and I guess I could use saveField after the main save to update the join field, but i'd like to know if there's a cleaner way. Many thanks Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
best way to do calculated fields in afterFind
Hi all, Is this the best way to create a calculated field in a model object? It works perfectly, but having to merge an array doesn't seem ideal, and it's not OO at all. function afterFind($results) { for ($i=0; $i < count($results); $i++) { $lens = $results[$i]['Lens']; $description = $lens['wide_zoom'] . '-' . $lens['long_zoom']; $lens = array_merge($lens, array('description' => $description)); $results[$i]['Lens'] = $lens; } return $results; } Many thanks Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---