saveField with invalid ID creates a blank record

2012-05-18 Thread Richard@Home
CakePHP 2:

Not noticed this behaviour before, is it by design? (Seems odd if it is...)

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(32) NOT NULL,
  `password` varchar(64) NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`),
  KEY `is_active` (`is_active`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;

(Notice in particular the NOT NULL flags on username  password:


class User extends AppModel {

public function activate($id) {

$this-User-id = $id;
$this-User-saveField('is_active', 1);

}

}

With an empty table:

$this-User-activate(1);

Creates a new user with an id of 1, an empty string for username and 
password, and is_active = 1;

I expected this to fail as User.id 1 doesn't exist.

$this-User-activate(99);

Creates a new user with an id of 2, an empty string for username and 
password, and is_active = 1;

I expected this to fail as User.id 99 doesn't exist.
Even if I disregard that user 99 doesn't exist, I'd expect the new record 
to be created with an id of 99 (not 2)

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: CakepHP 2.0 plugins no longer have a default controller?

2011-11-14 Thread Richard@Home
Just in case anyone else is looking for the answer to this:

I posted a ticket on CakePHP's issue tracker:

http://cakephp.lighthouseapp.com/projects/42648/tickets/2237-20-plugins-dont-have-a-default-controller

To which Mark responded and updated the migration guide:

http://book.cakephp.org/2.0/en/appendices/2-0-migration-guide.html?highlight=migration#router


On Oct 26, 7:33 pm, vaughany paulie...@gmail.com wrote:
 I thought this was just how plugins worked! Glad to hear it's (probably)
 not.

 Was linking to /users/users/view/id (as that was what worked) instead of
 the more preferable /users/view/id.

 Would dearly love to know how to use the preferable route.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Overriding form helper error messages in CakePHP 2.0

2011-10-28 Thread Richard@Home
Shamless bump!

On Oct 24, 3:44 pm, Richard@Home richardath...@gmail.com wrote:
 Hi all.

 I have the following $validate in my User model:

         var $validate = array(
                 'email'=array(
                         'required'=array(
                                 'rule'='notEmpty',
                                 'message'='cannot be blank'
                         ),
                         'email'=array(
                                 'rule'='email',
                                 'message'='must be a valid email address'
                         ),
                         'unique'=array(
                                 'rule'='isUnique',
                                 'message'='that email is already in use'
                         )
                 ),
                 'password'=array(
                         'required'=array(
                                 'rule'='notEmpty',
                                 'message'='cannot be blank'
                         ),
                         'length'=array(
                                 'rule'=array('minLength', 6),
                                 'message'='must be at least 6 letters, 
 numbers or symbols'
                         ),
                         'matches'=array(
                                 'rule'='passwordsMatch',
                                 'message'='passwords do not match'
                         )
                 )
         );

 And I'm trying to override the 'unique' email address message in my
 form with:

 echo $this-Form-input('User.email', array(
         'error'=array(
                 'unique' = 'That email is already in use. Have you ' . 
 $this-Html-link('forgotten your password',

 array('action'='forgotten_password')) . '?'
         )
 ));

 But it's still displaying the default validate message, not the custom
 one.

 What am I doing wrong?

 Thanks in advance.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: CakePHP 2.0 upgrade - benefit vs pain scale

2011-10-27 Thread Richard@Home
I'm also upgrading a 1.3 app but it's proving to be problematic :-S

I'd say if you aren't too far along in your project then upgrade, but
If you're using custom plugins and behaviors prepare for a bit of hair
pulling ;-)

On Oct 27, 1:38 pm, Shukuboy shuku...@gmail.com wrote:
 Hi guys,

 I have already started my first project in Cake 1.3, and have managed
 to set everything up the way I want it, that includes the basics,
 authentication, unit testing, i18n and a few other things.

 I had a look at the change logs of Cake 2.0 and all the updates look
 like good stuff.   However I'm not sure if upgrading at this point of
 time would be so wise as it'd mean upgrading a whole lot of
 components, behaviors, tests and may end up costing a lot of time in
 the future, due to lack of compatibility with existing plugins written
 for 1.3.

 Hence, I was wondering about your opinion on these :
 -  Are the non-tangible benefits of Cake 2.0 (such as performance and
 code clean-ness) worth the pain of upgrading ?
 -  How much effort was involved in upgrading all your stuff to 2.0 ?
 -  What's your experience been like so far with the new framework ?

 Cheers,
 Shukuboy

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


CakePHP 2.0 - Using a different/unconnected model in a behavior

2011-10-27 Thread Richard@Home
Hi all

I'm currently re-writing a 1.3 behavior which handles custom routing

In my 1.3 Routable behavior I could pull in a reference to the Route
model in a method with:

App::Import('Model', 'Route');
$Route = new Route();

And access it with: $data = $Route-find('all', ... );

I've tried the same thing in 2.0 but I get the following error:

Fatal error: Class 'Route' not found

on the $Route = new Route() line

I've tried using:

App::uses('Route', 'Model');

and that gives the same error.

How do I load a model to use in a behavior method?

Thanks in advance.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: CakePHP 2.0 - Using a different/unconnected model in a behavior

2011-10-27 Thread Richard@Home
Found the solution myself:

App::uses('Route', 'Model');

needs to go before the class definition in the Behavior, not inside a
method.

ie.

App::uses('Route', 'Model');

class Routable extends ModelBehavior {

   public function foo() {

 $Route = new Route();

   }

}

On Oct 27, 3:35 pm, Richard@Home richardath...@gmail.com wrote:
 Hi all

 I'm currently re-writing a 1.3 behavior which handles custom routing

 In my 1.3 Routable behavior I could pull in a reference to the Route
 model in a method with:

 App::Import('Model', 'Route');
 $Route = new Route();

 And access it with: $data = $Route-find('all', ... );

 I've tried the same thing in 2.0 but I get the following error:

 Fatal error: Class 'Route' not found

 on the $Route = new Route() line

 I've tried using:

 App::uses('Route', 'Model');

 and that gives the same error.

 How do I load a model to use in a behavior method?

 Thanks in advance.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


CakepHP 2.0 plugins no longer have a default controller?

2011-10-26 Thread Richard@Home
In CakePHP 1.3 you can have a default controller for your plugins.

e.g. if you had a Users plugin, you could create a users_controller so
that urls such as:

/users/index
/users/edit/2

mapped to the index/edit actions in the Users controller in the Users
plugin

In CakePHP 2.0 you no longer seem to be able to do this and now need
to use urls such as:

/users/users/index
/users/users/edit/2

I've tried messing around with custom routing to mimic the 1.3
behavior but with no luck so far.

Was this intentionally removed from 2.0 or am I missing something?

Thanks in advance.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: CakepHP 2.0 plugins no longer have a default controller?

2011-10-26 Thread Richard@Home
Thanks for the sanity check. Didn't change anything and it's working
now :-o

I'm putting it down to a temporary caching issue or lackOfCoffee
exception!


On Oct 26, 3:58 pm, designv...@gmail.com designv...@gmail.com
wrote:
 I have an 'Accommodation' plugin

 with AccommodationController.php

 and it works fine..?

 d//t.

 On Oct 26, 3:52 pm, Richard@Home richardath...@gmail.com wrote:







  In CakePHP 1.3 you can have a default controller for your plugins.

  e.g. if you had a Users plugin, you could create a users_controller so
  that urls such as:

  /users/index
  /users/edit/2

  mapped to the index/edit actions in the Users controller in the Users
  plugin

  In CakePHP 2.0 you no longer seem to be able to do this and now need
  to use urls such as:

  /users/users/index
  /users/users/edit/2

  I've tried messing around with custom routing to mimic the 1.3
  behavior but with no luck so far.

  Was this intentionally removed from 2.0 or am I missing something?

  Thanks in advance.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: CakepHP 2.0 plugins no longer have a default controller?

2011-10-26 Thread Richard@Home
meh, no its not. Working for prefixed routes, but not for others

E.g., I have a register() method in my users controller,

Can't reach it with:

/users/register

gives:

Error: Users.RegisterController could not be found.

Error: Create the class RegisterController below in file: /home/
richarda/www/test/cake_zero/www/app/Plugin/Users/Controller/
RegisterController.php

Can be reached at:
/users/users/register

/admin/users/index renders the users controller admin_index() method
correctly.


On Oct 26, 3:58 pm, designv...@gmail.com designv...@gmail.com
wrote:
 I have an 'Accommodation' plugin

 with AccommodationController.php

 and it works fine..?

 d//t.

 On Oct 26, 3:52 pm, Richard@Home richardath...@gmail.com wrote:







  In CakePHP 1.3 you can have a default controller for your plugins.

  e.g. if you had a Users plugin, you could create a users_controller so
  that urls such as:

  /users/index
  /users/edit/2

  mapped to the index/edit actions in the Users controller in the Users
  plugin

  In CakePHP 2.0 you no longer seem to be able to do this and now need
  to use urls such as:

  /users/users/index
  /users/users/edit/2

  I've tried messing around with custom routing to mimic the 1.3
  behavior but with no luck so far.

  Was this intentionally removed from 2.0 or am I missing something?

  Thanks in advance.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Overriding form helper error messages in CakePHP 2.0

2011-10-24 Thread Richard@Home
Hi all.

I have the following $validate in my User model:

var $validate = array(
'email'=array(
'required'=array(
'rule'='notEmpty',
'message'='cannot be blank'
),
'email'=array(
'rule'='email',
'message'='must be a valid email address'
),
'unique'=array(
'rule'='isUnique',
'message'='that email is already in use'
)
),
'password'=array(
'required'=array(
'rule'='notEmpty',
'message'='cannot be blank'
),
'length'=array(
'rule'=array('minLength', 6),
'message'='must be at least 6 letters, numbers 
or symbols'
),
'matches'=array(
'rule'='passwordsMatch',
'message'='passwords do not match'
)
)
);


And I'm trying to override the 'unique' email address message in my
form with:

echo $this-Form-input('User.email', array(
'error'=array(
'unique' = 'That email is already in use. Have you ' . 
$this-Html-
link('forgotten your password',
array('action'='forgotten_password')) . '?'
)
));



But it's still displaying the default validate message, not the custom
one.

What am I doing wrong?

Thanks in advance.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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