Re: ActiveRecord getting resource instead of dataset

2010-11-05 Thread Adrian Arnautu
Hi,

Thank you for reply.

I already limit my results but this is not the issue I raise. :)
Basically, I want to do it 'old school', something like:
$resource = $this->Model->getResource($query_conditions);
while ($row = $this->Model->fetchRow($resource)) {
// do something
}

So far I didn't find anything in docs, looks like I'll have to dig in the
source code for the answer. Hope that there is a way to do this.

Cheers,
Adrian

On Fri, Nov 5, 2010 at 6:18 PM, cricket  wrote:

> On Fri, Nov 5, 2010 at 4:19 AM, Adrian Arnautu 
> wrote:
> > Hello to everyone,
> > Is there a way to get a resource and then fetch a row at a time from it
> > instead of getting the whole rows in one structure?
> > For a small dataset it's relatively fine, but when this dataset is
> growing
> > (for example, you want to generate a CSV having ~ 5-6k rows or maybe
> more)
> > it looks overkilling in terms of memory requirements.
> > I know that the possible answer is somewhere in the source code, I want
> to
> > know if any of you used this approach.
>
> You could set 'limit' in your find() and loop until it returns no more
> results. Don't forget to set the offset, of course.
>
> Or, I suppose you could use paginate() as well, changing the 'page'
> param each iteration.
>
> 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.comFor
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

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: Auto-fill Date Values In Form

2010-11-05 Thread cricket
On Fri, Nov 5, 2010 at 12:33 AM, Adam  wrote:
> Thanks Paul,
>
> I really wanted it in a standard, form-helper format -  - MM - DD
> drop-downs.
>
> I spent more time on it than i wanted to so in the end I just exploded
> the date value from the DB and manually assigned them each to day,
> month and year form-inputs with their set values.
>
> Like I said before, this has never been a problem for me in the past,
> but It was with code that someone else had built before me, so maybe
> I'll use that as an excuse ; )

I just tested in 1.3.5 and it worked fine:

echo $this->Form->dateTime('Site.created', 'YMD');

Note what the docs say:
http://book.cakephp.org/view/1418/dateTime
dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12',
$selected = null, $attributes = array())

"You also can pre-select the current datetime by setting $selected =
null and $attributes = array("empty" => false)"

You can see, above, that I did pass null for the $selected param.
However, I did not pass false for 'empty'. Perhaps your problem lies
there.

No, wait. If I do:

echo $this->Form->dateTime('Site.created', 'YMD', '24', null, array());

... I still get the value from the DB. Change that to:

echo $this->Form->dateTime('Site.created', 'YMD', '24', null,
array('empty' => false));

... of course, I still get the correct value, because it's set. Are
you certain that you're using the correct field, and that it
definitely has a value? DO a debug($this->data) in your form view to
be sure.

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: ActiveRecord getting resource instead of dataset

2010-11-05 Thread cricket
On Fri, Nov 5, 2010 at 4:19 AM, Adrian Arnautu  wrote:
> Hello to everyone,
> Is there a way to get a resource and then fetch a row at a time from it
> instead of getting the whole rows in one structure?
> For a small dataset it's relatively fine, but when this dataset is growing
> (for example, you want to generate a CSV having ~ 5-6k rows or maybe more)
> it looks overkilling in terms of memory requirements.
> I know that the possible answer is somewhere in the source code, I want to
> know if any of you used this approach.

You could set 'limit' in your find() and loop until it returns no more
results. Don't forget to set the offset, of course.

Or, I suppose you could use paginate() as well, changing the 'page'
param each iteration.

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: ACL and Auth: Check if logged in user has same ID as passed by the URL? --psybear

2010-11-05 Thread cricket
See these two recent posts:
http://groups.google.com/group/cake-php/browse_thread/thread/942ffc4f0fc789d4#
http://groups.google.com/group/cake-php/browse_thread/thread/6987c6438f49bfc8#

On Fri, Nov 5, 2010 at 10:23 AM, psybear83  wrote:
> Hi everybody
>
> My application uses ACL and Auth. Every user should be able to edit
> his own profile. For this I check on every request whether the
> currently logged in user is the same as the one who's ID was submitted
> in the URL (users/edit/123).
>
> The following method existed in the app since early CakePHP 1.2.x
> days...
>
>        function _userIsSelfOrSuperuser() {
>                if ($this->isSuperuser()) {
>                        return true;
>                } else {
>                        $this->User->read();
>                        if (!empty($this->User->data)) {
>                          $user = $this->Auth->user();
>                                return $user['User']['id'] == 
> $this->User->data['User']['id'];
>                        } else {
>                                return false;
>                        }
>                }
>        }
>
> Sadly, it doesn't work anymore on CakePHP 1.3.5 (I don't know if it
> *ever* worked, it's not my app).
>
> I guess the problem is the $this->User->read() line: this one does
> absolutely nothing, because $this->User->id is not set. Maybe in
> earlier version this ID was set automatially when an ID was submit
> throught the URL (123)?
>
> My question: how should I fix this? I could do
>
> $this->User->id = $this->params['passed][0];
>
> because the user's ID should usually be the first unnamed passed
> parameter... but this looks very awkward to me, and when requesting
> users/index the param isn't even populated.
>
> So I guess there's a cleaner way to solve this? Maybe there's
> something like
>
> $this->User->id = $this->idOfTheObjectThatWasSubmitForEditOrAdd();
>
> or something...? ;-)
>
> Thanks a lot for your help, guys!
> Josh
>
> 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
>

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: Tree Behavior

2010-11-05 Thread cricket
On Thu, Nov 4, 2010 at 11:37 PM, Meroe  wrote:
> Hello folks,
>
> I'm working with the tree behavior and having issues getting the
> results to display more than the 'name' field in my table.  I have
> many additional fields that I've added and would like to display in
> the view such as 'start_date','details'.  If I print_r the $nodelist I
> see:
>
> Array ( [52] => Task #1 [54] => - Sub Task of Task #1 [53] => Task
> #2 )
>
> Here is my model:
>  class Projecttask extends AppModel {
>        var $name = 'Projecttask';
>        var $actsAs = array('Tree');
> }
> ?>
>
> Here is my Controller:
> function index() {
>         $nodelist = $this->Projecttask->generatetreelist(null,null,null," -
> ");
>     $this->set('nodelist',$nodelist);
>        }


You're using the wrong method. Look at the API:
http://api.cakephp.org/class/tree-behavior#method-TreeBehaviorgeneratetreelist

"A convenience method for returning a hierarchical array used for HTML
select boxes"

IOW, it returns data in the same format as find('list'), ie. $id =>
$name. You should use find('threaded', $filters), where $filters is an
array with the usual 'conditions', 'fields', etc. arrays. You can even
use 'contain' as you would normally. Each Projecttask (shouldn't that
be ProjectTask?) entry will have a 'children' key pointing to an array
of Projecttasks (if any).


> Here is my View:
>  echo "";
> foreach($nodelist as $key=>$value){
>    $editurl = $html->link("Edit", array('action'=>'edit', $key));
>    $upurl = $html->link("Up", array('action'=>'moveup', $key));
>    $downurl = $html->link("Down", array('action'=>'movedown', $key));
>    $deleteurl = $html->link("Delete", array('action'=>'delete',
> $key));
>    echo "[$editurl|$upurl|$downurl|$deleteurl] $value";
> }
> echo "";
> ?>

You should take a look at Andy Dawson's TreeHelper, which takes the
pain out of creating nested lists from nested tree data. I found it a
bit confusing at first but it works great.
http://bakery.cakephp.org/articles/AD7six/2008/01/24/tree-helper-1

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: ACL and Auth: Check if logged in user has same ID as passed by the URL? --psybear

2010-11-05 Thread Jeremy Burns | Class Outfit
You can check against $this->Auth->User-id to make sure the user id of the 
profile they want to edit matches. That way you are not relying on parameters 
passed in via a url.

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 5 Nov 2010, at 10:23, psybear83 wrote:

> Hi everybody
> 
> My application uses ACL and Auth. Every user should be able to edit
> his own profile. For this I check on every request whether the
> currently logged in user is the same as the one who's ID was submitted
> in the URL (users/edit/123).
> 
> The following method existed in the app since early CakePHP 1.2.x
> days...
> 
>   function _userIsSelfOrSuperuser() {
>   if ($this->isSuperuser()) {
>   return true;
>   } else {
>   $this->User->read();
>   if (!empty($this->User->data)) {
> $user = $this->Auth->user();
>   return $user['User']['id'] == 
> $this->User->data['User']['id'];
>   } else {
>   return false;
>   }
>   }
>   }
> 
> Sadly, it doesn't work anymore on CakePHP 1.3.5 (I don't know if it
> *ever* worked, it's not my app).
> 
> I guess the problem is the $this->User->read() line: this one does
> absolutely nothing, because $this->User->id is not set. Maybe in
> earlier version this ID was set automatially when an ID was submit
> throught the URL (123)?
> 
> My question: how should I fix this? I could do
> 
> $this->User->id = $this->params['passed][0];
> 
> because the user's ID should usually be the first unnamed passed
> parameter... but this looks very awkward to me, and when requesting
> users/index the param isn't even populated.
> 
> So I guess there's a cleaner way to solve this? Maybe there's
> something like
> 
> $this->User->id = $this->idOfTheObjectThatWasSubmitForEditOrAdd();
> 
> or something...? ;-)
> 
> Thanks a lot for your help, guys!
> Josh
> 
> 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

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: build_acl() method creates too much acos! How to make non-action-methods private? --psybear

2010-11-05 Thread AD7six


On Nov 5, 4:02 pm, Joshua Muheim  wrote:
> Hey AD7six, thanks for your very detailed answer!
>
> > You seem to have tens or hunderds of methods in your controllers e,g,
>
> Yes, that's true, I'm working on renaming them to protected ones using
> "_" as prefix.
>
> >  isSuperuser <- user model
> >  afterView <- model
> >  OR
> >    if more relevant just put it in the action, where's the benfit of
> > having 2 view functions
>
> I don't really understand. isSuperuser should be a model method, I
> agree with this, too. But what about afterView being a model method?
> In my concrete scenario, I have an AppController::view() method that
> handles all the view logic for every descending controller, and in the
> end of this view method the afterView() method is called, so
> descending controllers can do some magic in them (I'm using the
> Template pattern here).

what's wrong with

function view($id = null) {
  parent::view($id);
  // stuff that was in afterView
}

It depends quite a bit on what's in it and IME having generic app
controller actions and logic similar to the above eventually
complicates, not simplifies, code.

>
> So what about "put it in the action" and having 2 view functions?
>
> > _ = protected, __ = private. It's a convetion for php4 compatibility,
> > and it doesn't make any difference (but I'd suggest you only use
> > protected).
>
> I guess I'll only use one underscore. I never worked with strictly
> visibility enforcing languages like Java too long, so I don't really
> have the "feeling" on when a method should be private or protected,
> anyway.

If in doubt, you want protected. Also note people often say private
when they really mean protected. a private function cannot be called
from a descendant object - e.g. with your current code if afterFind
was declared private in the app controller and you haven't overwritten
it in your descendent controller - you can't access it and php will
die telling you so.

hth,

AD

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: build_acl() method creates too much acos! How to make non-action-methods private? --psybear

2010-11-05 Thread Joshua Muheim
2010/11/5 Antonio Gázquez :
> I use a similar method but i filter the methods I'll use by using a form. I
> took the example from the book "practical cakephp projects" (great book btw)
> and tweaked it a bit. I can upload the code to pastebin if you want.

This would be nice, thank you! :-)

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: build_acl() method creates too much acos! How to make non-action-methods private? --psybear

2010-11-05 Thread Joshua Muheim
Hey AD7six, thanks for your very detailed answer!

> You seem to have tens or hunderds of methods in your controllers e,g,

Yes, that's true, I'm working on renaming them to protected ones using
"_" as prefix.

>  isSuperuser <- user model
>  afterView <- model
>  OR
>    if more relevant just put it in the action, where's the benfit of
> having 2 view functions

I don't really understand. isSuperuser should be a model method, I
agree with this, too. But what about afterView being a model method?
In my concrete scenario, I have an AppController::view() method that
handles all the view logic for every descending controller, and in the
end of this view method the afterView() method is called, so
descending controllers can do some magic in them (I'm using the
Template pattern here).

So what about "put it in the action" and having 2 view functions?

> _ = protected, __ = private. It's a convetion for php4 compatibility,
> and it doesn't make any difference (but I'd suggest you only use
> protected).

I guess I'll only use one underscore. I never worked with strictly
visibility enforcing languages like Java too long, so I don't really
have the "feeling" on when a method should be private or protected,
anyway.

> If you drop the acos table that means any existing permisions you've
> got are useless - because most likly the aco_ids will change. That's
> most likely not what you want.

That's right, thank you!

> PS. use visibility keywords - if you do so you'll recognise the use/
> difference between e.g.
>  protected function _someCommonController method()
>  public function _calledFromADifferentObject() <- e.g. blackhole must
> be public but is not an action.

But this will only work with PHP5, right? My whole app is written in
PHP4 style code, so I guess I will stick to that...

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: integrating - swfUpload or Uploadify doesn't work

2010-11-05 Thread chris
Would be interested in if you get this working and how you went about
it. I think something like this would be useful on my current project.

I found this on the Bakery, but it is outdated.

http://bakery.cakephp.org/articles/jrevillini/2007/04/10/swfupload-and-multipurpose-uploader

I notice the top comment mentions a problem with the auth component,
this might be a place to look?

Failing that, are there any altenerative upload methods that could be
used?

On Nov 3, 3:45 pm, lordojazz  wrote:
> Hello I'm having a hard time implementing swf upload on my app, I'm
> using SWFUpload v2.2.0.1 and CakePHP 1.3.4 but it seems like the it
> doesn't call my controller action where the ftp upload functionality
> is...
>
> I have tried creating swfupload Component as well it is just simple
> ftp upload... without the swfupload or uploadify the component works
> properly.
>
> can any one help me with this issue please.

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: build_acl() method creates too much acos! How to make non-action-methods private? --psybear

2010-11-05 Thread Antonio Gázquez
I use a similar method but i filter the methods I'll use by using a form. I
took the example from the book "practical cakephp projects" (great book btw)
and tweaked it a bit. I can upload the code to pastebin if you want.

Regards

2010/11/5 psybear83 

> Hi everybody
>
> I wanted to update my ACOs table and found this useful build_acl()
> method from
>
> http://book.cakephp.org/view/647/An-Automated-tool-for-creating-ACOs
>
> I ran it, and it produced the following:
>
>[0] => Created Aco node for controllers
>[1] => Created Aco node for Pages
>[2] => Created Aco node for display
>[3] => Created Aco node for blackHole
>[4] => Created Aco node for isSuperuser
>[5] => Created Aco node for indexFind
>[6] => Created Aco node for index
>[7] => Created Aco node for indexMenu
>[8] => Created Aco node for search
>[9] => Created Aco node for count
>[10] => Created Aco node for autoComplete
>[11] => Created Aco node for add
>[12] => Created Aco node for afterAdd
>[13] => Created Aco node for view
>[14] => Created Aco node for afterView
>[15] => Created Aco node for edit
>[16] => Created Aco node for afterEdit
>[17] => Created Aco node for delete
>[18] => Created Aco node for Applications
>[19] => Created Aco node for indexFind
>[20] => Created Aco node for index
>[21] => Created Aco node for getDocumentation
>[22] => Created Aco node for blackHole
>[23] => Created Aco node for isSuperuser
>[24] => Created Aco node for indexMenu
>[25] => Created Aco node for search
>[26] => Created Aco node for count
>[27] => Created Aco node for autoComplete
>[28] => Created Aco node for add
>[29] => Created Aco node for afterAdd
>[30] => Created Aco node for view
>[31] => Created Aco node for afterView
>[32] => Created Aco node for edit
>[33] => Created Aco node for afterEdit
>[34] => Created Aco node for delete
>[35] => Created Aco node for Authors
>[36] => Created Aco node for blackHole
>[37] => Created Aco node for isSuperuser
>[38] => Created Aco node for indexFind
>[39] => Created Aco node for index
>[40] => Created Aco node for indexMenu
>[41] => Created Aco node for search
>[42] => Created Aco node for count
>[43] => Created Aco node for autoComplete
>[44] => Created Aco node for add
>[45] => Created Aco node for afterAdd
>[46] => Created Aco node for view
>[47] => Created Aco node for afterView
>[48] => Created Aco node for edit
>[49] => Created Aco node for afterEdit
>[50] => Created Aco node for delete
>[51] => Created Aco node for Contracts
>[52] => Created Aco node for afterAdd
>[53] => Created Aco node for afterEdit
>[54] => Created Aco node for blackHole
>[55] => Created Aco node for isSuperuser
>[56] => Created Aco node for indexFind
>[57] => Created Aco node for index
>[58] => Created Aco node for indexMenu
>[59] => Created Aco node for search
>[60] => Created Aco node for count
>[61] => Created Aco node for autoComplete
>[62] => Created Aco node for add
>[63] => Created Aco node for view
>[64] => Created Aco node for afterView
>[65] => Created Aco node for edit
>[66] => Created Aco node for delete
>[67] => Created Aco node for DetailRoles
>[68] => Created Aco node for blackHole
>[69] => Created Aco node for isSuperuser
>[70] => Created Aco node for indexFind
>[71] => Created Aco node for index
>[72] => Created Aco node for indexMenu
>[73] => Created Aco node for search
>[74] => Created Aco node for count
>[75] => Created Aco node for autoComplete
>[76] => Created Aco node for add
>[77] => Created Aco node for afterAdd
>[78] => Created Aco node for view
>[79] => Created Aco node for afterView
>[80] => Created Aco node for edit
>[81] => Created Aco node for afterEdit
>[82] => Created Aco node for delete
>[83] => Created Aco node for GlobalLocations
>[84] => Created Aco node for blackHole
>[85] => Created Aco node for isSuperuser
>[86] => Created Aco node for indexFind
>[87] => Created Aco node for index
>[88] => Created Aco node for indexMenu
>[89] => Created Aco node for search
>[90] => Created Aco node for count
>[91] => Created Aco node for autoComplete
>[92] => Created Aco node for add
>[93] => Created Aco node for afterAdd
>[94] => Created Aco node for view
>[95] => Created Aco node for afterView
>[96] => Created Aco node for edit
>[97] => Created Aco node for afterEdit
>[98] => Created Aco node for delete
>[99] => Created Aco node for Groups
>[100] => Created Aco node for afterAdd
>[101] => Created Aco node for afterEdit
>[102] => Created Aco node for index
>[103] => Created Aco node for build_acl
>[104] => Created Aco node for blackHole
>[105] => Created Aco node for isSuperuser
>[106] => C

cakePHP 1.2.3 and PHPUnit

2010-11-05 Thread Karthik
I am a cake and a PHP newbie so apologies if these question is too
basic.

I am trying to integrate PHPUnit with cakePHP 1.2.3. In
cake_test_case.php, I made the following changes:

(1) In cake_test_case.php, class CakeTestCase extends from
PHPUnit_Framework_TestCase

(2) I added require_once 'PHPUnit/Framework/TestCase.php' to
cake_test_case.php

Questions:
(1) Do I still need app::import('Vendor', 'PHPUnit')? Right now I dont
have that in my code.
(2) When I run my PHPUnit test case which is derived from
CakeTestCase, I see the following error message:

Warning: require(CAKEdispatcher.php): failed to open stream: No such
file or directory in /home/karthik/work/livemocha/trunk/src/wwwroot/
cake/tests/lib/cake_test_case.php on line 31

So for some reason, unknown to me, the cake constants defined in
paths.php are not getting read. This leads me to believe that cake is
not getting initialized. May be I am missing some intermediate steps
here.

Any suggestions?

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


ACL and Auth: Check if logged in user has same ID as passed by the URL? --psybear

2010-11-05 Thread psybear83
Hi everybody

My application uses ACL and Auth. Every user should be able to edit
his own profile. For this I check on every request whether the
currently logged in user is the same as the one who's ID was submitted
in the URL (users/edit/123).

The following method existed in the app since early CakePHP 1.2.x
days...

function _userIsSelfOrSuperuser() {
if ($this->isSuperuser()) {
return true;
} else {
$this->User->read();
if (!empty($this->User->data)) {
  $user = $this->Auth->user();
return $user['User']['id'] == 
$this->User->data['User']['id'];
} else {
return false;
}
}
}

Sadly, it doesn't work anymore on CakePHP 1.3.5 (I don't know if it
*ever* worked, it's not my app).

I guess the problem is the $this->User->read() line: this one does
absolutely nothing, because $this->User->id is not set. Maybe in
earlier version this ID was set automatially when an ID was submit
throught the URL (123)?

My question: how should I fix this? I could do

$this->User->id = $this->params['passed][0];

because the user's ID should usually be the first unnamed passed
parameter... but this looks very awkward to me, and when requesting
users/index the param isn't even populated.

So I guess there's a cleaner way to solve this? Maybe there's
something like

$this->User->id = $this->idOfTheObjectThatWasSubmitForEditOrAdd();

or something...? ;-)

Thanks a lot for your help, guys!
Josh

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: build_acl() method creates too much acos! How to make non-action-methods private? --psybear

2010-11-05 Thread AD7six


On Nov 5, 11:31 am, psybear83  wrote:
> Hi everybody
>
> I wanted to update my ACOs table and found this useful build_acl()
> method from
>
> http://book.cakephp.org/view/647/An-Automated-tool-for-creating-ACOs
>
> I ran it, and it produced the following:
>
>     [0] => Created Aco node for controllers
>     [1] => Created Aco node for Pages
>     [2] => Created Aco node for display
>     [3] => Created Aco node for blackHole
>     [4] => Created Aco node for isSuperuser
>     [5] => Created Aco node for indexFind
>     [6] => Created Aco node for index
>     [7] => Created Aco node for indexMenu
>     [8] => Created Aco node for search
>     [9] => Created Aco node for count
>     [10] => Created Aco node for autoComplete
>     [11] => Created Aco node for add
>     [12] => Created Aco node for afterAdd
>     [13] => Created Aco node for view
>     [14] => Created Aco node for afterView
>     [15] => Created Aco node for edit
>     [16] => Created Aco node for afterEdit
>     [17] => Created Aco node for delete
>     [18] => Created Aco node for Applications
>     [19] => Created Aco node for indexFind
>     [20] => Created Aco node for index
>     [21] => Created Aco node for getDocumentation
>     [22] => Created Aco node for blackHole
>     [23] => Created Aco node for isSuperuser
>     [24] => Created Aco node for indexMenu
>     [25] => Created Aco node for search
>     [26] => Created Aco node for count
>     [27] => Created Aco node for autoComplete
>     [28] => Created Aco node for add
>     [29] => Created Aco node for afterAdd
>     [30] => Created Aco node for view
>     [31] => Created Aco node for afterView
>     [32] => Created Aco node for edit
>     [33] => Created Aco node for afterEdit
>     [34] => Created Aco node for delete
>     [35] => Created Aco node for Authors
>     [36] => Created Aco node for blackHole
>     [37] => Created Aco node for isSuperuser
>     [38] => Created Aco node for indexFind
>     [39] => Created Aco node for index
>     [40] => Created Aco node for indexMenu
>     [41] => Created Aco node for search
>     [42] => Created Aco node for count
>     [43] => Created Aco node for autoComplete
>     [44] => Created Aco node for add
>     [45] => Created Aco node for afterAdd
>     [46] => Created Aco node for view
>     [47] => Created Aco node for afterView
>     [48] => Created Aco node for edit
>     [49] => Created Aco node for afterEdit
>     [50] => Created Aco node for delete
>     [51] => Created Aco node for Contracts
>     [52] => Created Aco node for afterAdd
>     [53] => Created Aco node for afterEdit
>     [54] => Created Aco node for blackHole
>     [55] => Created Aco node for isSuperuser
>     [56] => Created Aco node for indexFind
>     [57] => Created Aco node for index
>     [58] => Created Aco node for indexMenu
>     [59] => Created Aco node for search
>     [60] => Created Aco node for count
>     [61] => Created Aco node for autoComplete
>     [62] => Created Aco node for add
>     [63] => Created Aco node for view
>     [64] => Created Aco node for afterView
>     [65] => Created Aco node for edit
>     [66] => Created Aco node for delete
>     [67] => Created Aco node for DetailRoles
>     [68] => Created Aco node for blackHole
>     [69] => Created Aco node for isSuperuser
>     [70] => Created Aco node for indexFind
>     [71] => Created Aco node for index
>     [72] => Created Aco node for indexMenu
>     [73] => Created Aco node for search
>     [74] => Created Aco node for count
>     [75] => Created Aco node for autoComplete
>     [76] => Created Aco node for add
>     [77] => Created Aco node for afterAdd
>     [78] => Created Aco node for view
>     [79] => Created Aco node for afterView
>     [80] => Created Aco node for edit
>     [81] => Created Aco node for afterEdit
>     [82] => Created Aco node for delete
>     [83] => Created Aco node for GlobalLocations
>     [84] => Created Aco node for blackHole
>     [85] => Created Aco node for isSuperuser
>     [86] => Created Aco node for indexFind
>     [87] => Created Aco node for index
>     [88] => Created Aco node for indexMenu
>     [89] => Created Aco node for search
>     [90] => Created Aco node for count
>     [91] => Created Aco node for autoComplete
>     [92] => Created Aco node for add
>     [93] => Created Aco node for afterAdd
>     [94] => Created Aco node for view
>     [95] => Created Aco node for afterView
>     [96] => Created Aco node for edit
>     [97] => Created Aco node for afterEdit
>     [98] => Created Aco node for delete
>     [99] => Created Aco node for Groups
>     [100] => Created Aco node for afterAdd
>     [101] => Created Aco node for afterEdit
>     [102] => Created Aco node for index
>     [103] => Created Aco node for build_acl
>     [104] => Created Aco node for blackHole
>     [105] => Created Aco node for isSuperuser
>     [106] => Created Aco node for indexFind
>     [107] => Created Aco node for indexMenu
>     [108] => Created Aco node

Re: Has One vs belongsTo and a weird table association

2010-11-05 Thread Jeremy Burns | Class Outfit
I would keep all user entities in a single table (users) as it means everything 
is in one place. I would have thought it would make the login and 
authentication process easier too. Can a shop owner own more than one shop? And 
can one shop have more than one owner? Perhaps you could do Shop 
$hasAndBelongsToMany User [owner]?

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 5 Nov 2010, at 08:25, Santiago Basulto wrote:

> Hello people.
> 
> I'm developing a Cake app and have a little problem. Let me tell you
> how is it organized first. The site i'm building  is about a "city
> shop guide", i mean, a site where you can search for shops. The issue
> is that there can be two types of users, which can be either "regular
> users" or "shop owners".
> 
> Regular users are people who enter the site and make searches. They
> can save shops in their personal "favorites" page and make some other
> things like leave comments.
> 
> Shop owners, are, people who owns a shop and upload information about
> it in the site.
> 
> So, i've thinking in two ways of creating this and use all the
> functionality of Auth and ACL.
> 
> The first one is to have a table "users", like regular, and in each
> "specific user", a reference to it something like this:
> 
> CREATE TABLE users(
>   id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
>   username VARCHAR(30),
>   password VARCHAR(50),
>   role VARCHAR(10),
>   PRIMARY KEY(id)
> );
> 
> CREATE TABLE shop(
>   id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
>   name VARCHAR(30),
>   address VARCHAR(50),
>   category SMALLINT,
>   user_id INTEGER UNSIGNED NOT NULL,
>   PRIMARY KEY(id)
> )
> 
> class shop extends AppModel{
> 
>   var $belongsTo  = array("user");
> 
>   // OR
> 
>   var $hasOne  = array("user");
> 
> }
> 
> Then, all users which have a "shop" associated can upload and edit
> information about the shop they owns. I think this would work well,
> but i don't know which type of association to include (belongsTo or
> hasOne).
> 
> Another approach would be
> 
> CREATE TABLE users(
>   id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
>   username VARCHAR(30),
>   password VARCHAR(50),
>   role VARCHAR(10),
>   shop_id INTEGER UNSIGNED NULL,  -- Nullable
>   regular_user_id INTEGER UNSIGNED NULL,   -- Nullable
>   PRIMARY KEY(id)
> );
> 
> CREATE TABLE shop(
>   id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
>   name VARCHAR(30),
>   address VARCHAR(50),
>   category SMALLINT,
>   user_id INTEGER UNSIGNED NOT NULL,
>   PRIMARY KEY(id)
> )
> 
> CREATE TABLE regular_user(
>   id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
>   name VARCHAR(30),
>   last_name VARCHAR(50),
>   email VARCHAR(50),
>   user_id INTEGER UNSIGNED NOT NULL,
>   PRIMARY KEY(id)
> )
> 
> Then, if a user can "know" which type of "user" is just reading it's
> not null field. This is a type of inheritence in database, that's
> broadly used.
> 
> So, what do you think guys? Do you have some expirience with this?
> 
> Thank you very much!
> 
> -- 
> Santiago Basulto.-
> 
> 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

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


Has One vs belongsTo and a weird table association

2010-11-05 Thread Santiago Basulto
Hello people.

I'm developing a Cake app and have a little problem. Let me tell you
how is it organized first. The site i'm building  is about a "city
shop guide", i mean, a site where you can search for shops. The issue
is that there can be two types of users, which can be either "regular
users" or "shop owners".

Regular users are people who enter the site and make searches. They
can save shops in their personal "favorites" page and make some other
things like leave comments.

Shop owners, are, people who owns a shop and upload information about
it in the site.

So, i've thinking in two ways of creating this and use all the
functionality of Auth and ACL.

The first one is to have a table "users", like regular, and in each
"specific user", a reference to it something like this:

CREATE TABLE users(
   id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
   username VARCHAR(30),
   password VARCHAR(50),
   role VARCHAR(10),
   PRIMARY KEY(id)
);

CREATE TABLE shop(
   id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
   name VARCHAR(30),
   address VARCHAR(50),
   category SMALLINT,
   user_id INTEGER UNSIGNED NOT NULL,
   PRIMARY KEY(id)
)

class shop extends AppModel{

   var $belongsTo  = array("user");

   // OR

   var $hasOne  = array("user");

}

Then, all users which have a "shop" associated can upload and edit
information about the shop they owns. I think this would work well,
but i don't know which type of association to include (belongsTo or
hasOne).

Another approach would be

CREATE TABLE users(
   id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
   username VARCHAR(30),
   password VARCHAR(50),
   role VARCHAR(10),
   shop_id INTEGER UNSIGNED NULL,  -- Nullable
   regular_user_id INTEGER UNSIGNED NULL,   -- Nullable
   PRIMARY KEY(id)
);

CREATE TABLE shop(
   id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
   name VARCHAR(30),
   address VARCHAR(50),
   category SMALLINT,
   user_id INTEGER UNSIGNED NOT NULL,
   PRIMARY KEY(id)
)

CREATE TABLE regular_user(
   id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
   name VARCHAR(30),
   last_name VARCHAR(50),
   email VARCHAR(50),
   user_id INTEGER UNSIGNED NOT NULL,
   PRIMARY KEY(id)
)

Then, if a user can "know" which type of "user" is just reading it's
not null field. This is a type of inheritence in database, that's
broadly used.

So, what do you think guys? Do you have some expirience with this?

Thank you very much!

-- 
Santiago Basulto.-

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: Ensuring uniqueness on application level

2010-11-05 Thread Jeremy Burns | Class Outfit
Good points about hosting. Whatever you do at the front end you are more than a 
bit hampered if you can't rely on talking to the database.

I'd say you shouldn't find a workaround for something so important. Even if you 
are using soft delete you still don't want the same [unique] key floating 
around twice - that is a nightmare waiting to happen. If you are using soft 
delete is suggests that someone can soft undelete - what happens if that 
produces a clash with another undeleted id?

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 5 Nov 2010, at 06:39, MissYeh wrote:

> First off.. if the DB connection sometimes (aka too often) breaks,
> then find a better host else it will give you lots more headache in
> the future. It is crucial to have the best server environment you can
> possibly get. I don't think isUnique will be of any use when your DB
> connection breaks.
> 
> An other option is to add another database. If one isn't reachable,
> then the other takes over. A failover database.
> 
> An other option is to cache all the unique values eg every time it
> gets updated. If there is no DB connection, then check the cached file
> to see if the name in it exists. If it doesn't, then let the user
> choose the name and continue register.
> 
> 
> 
> On Nov 5, 9:23 am, Éber  wrote:
>> Hey guys!
>> 
>> I'm having a little bit of trouble with validation on my models. That
>> is because I'm using isUnique on some fields, but I didn't defined the
>> fields as unique keys on the DB (I'm using MySQL). I can't make them
>> unique keys right now because I'm using soft deletion on these models.
>> 
>> The thing is that, sometimes the DB connection will break, and
>> isUnique won't return a valid value, making it possible for my users
>> to register things with the same name, which is causing a lot of
>> trouble for me. I was trying to think in a way to ensure that, even
>> when the DB fails, I get some sort of good value from isUnique, so the
>> user won't be able to register with a duplicated name...
>> 
>> Does anyone have any hints on how can I do this the best way possible?
>> 
>> Thanks!
> 
> 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

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: Ensuring uniqueness on application level

2010-11-05 Thread MissYeh
First off.. if the DB connection sometimes (aka too often) breaks,
then find a better host else it will give you lots more headache in
the future. It is crucial to have the best server environment you can
possibly get. I don't think isUnique will be of any use when your DB
connection breaks.

An other option is to add another database. If one isn't reachable,
then the other takes over. A failover database.

An other option is to cache all the unique values eg every time it
gets updated. If there is no DB connection, then check the cached file
to see if the name in it exists. If it doesn't, then let the user
choose the name and continue register.



On Nov 5, 9:23 am, Éber  wrote:
> Hey guys!
>
> I'm having a little bit of trouble with validation on my models. That
> is because I'm using isUnique on some fields, but I didn't defined the
> fields as unique keys on the DB (I'm using MySQL). I can't make them
> unique keys right now because I'm using soft deletion on these models.
>
> The thing is that, sometimes the DB connection will break, and
> isUnique won't return a valid value, making it possible for my users
> to register things with the same name, which is causing a lot of
> trouble for me. I was trying to think in a way to ensure that, even
> when the DB fails, I get some sort of good value from isUnique, so the
> user won't be able to register with a duplicated name...
>
> Does anyone have any hints on how can I do this the best way possible?
>
> Thanks!

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


build_acl() method creates too much acos! How to make non-action-methods private? --psybear

2010-11-05 Thread psybear83
Hi everybody

I wanted to update my ACOs table and found this useful build_acl()
method from

http://book.cakephp.org/view/647/An-Automated-tool-for-creating-ACOs

I ran it, and it produced the following:

[0] => Created Aco node for controllers
[1] => Created Aco node for Pages
[2] => Created Aco node for display
[3] => Created Aco node for blackHole
[4] => Created Aco node for isSuperuser
[5] => Created Aco node for indexFind
[6] => Created Aco node for index
[7] => Created Aco node for indexMenu
[8] => Created Aco node for search
[9] => Created Aco node for count
[10] => Created Aco node for autoComplete
[11] => Created Aco node for add
[12] => Created Aco node for afterAdd
[13] => Created Aco node for view
[14] => Created Aco node for afterView
[15] => Created Aco node for edit
[16] => Created Aco node for afterEdit
[17] => Created Aco node for delete
[18] => Created Aco node for Applications
[19] => Created Aco node for indexFind
[20] => Created Aco node for index
[21] => Created Aco node for getDocumentation
[22] => Created Aco node for blackHole
[23] => Created Aco node for isSuperuser
[24] => Created Aco node for indexMenu
[25] => Created Aco node for search
[26] => Created Aco node for count
[27] => Created Aco node for autoComplete
[28] => Created Aco node for add
[29] => Created Aco node for afterAdd
[30] => Created Aco node for view
[31] => Created Aco node for afterView
[32] => Created Aco node for edit
[33] => Created Aco node for afterEdit
[34] => Created Aco node for delete
[35] => Created Aco node for Authors
[36] => Created Aco node for blackHole
[37] => Created Aco node for isSuperuser
[38] => Created Aco node for indexFind
[39] => Created Aco node for index
[40] => Created Aco node for indexMenu
[41] => Created Aco node for search
[42] => Created Aco node for count
[43] => Created Aco node for autoComplete
[44] => Created Aco node for add
[45] => Created Aco node for afterAdd
[46] => Created Aco node for view
[47] => Created Aco node for afterView
[48] => Created Aco node for edit
[49] => Created Aco node for afterEdit
[50] => Created Aco node for delete
[51] => Created Aco node for Contracts
[52] => Created Aco node for afterAdd
[53] => Created Aco node for afterEdit
[54] => Created Aco node for blackHole
[55] => Created Aco node for isSuperuser
[56] => Created Aco node for indexFind
[57] => Created Aco node for index
[58] => Created Aco node for indexMenu
[59] => Created Aco node for search
[60] => Created Aco node for count
[61] => Created Aco node for autoComplete
[62] => Created Aco node for add
[63] => Created Aco node for view
[64] => Created Aco node for afterView
[65] => Created Aco node for edit
[66] => Created Aco node for delete
[67] => Created Aco node for DetailRoles
[68] => Created Aco node for blackHole
[69] => Created Aco node for isSuperuser
[70] => Created Aco node for indexFind
[71] => Created Aco node for index
[72] => Created Aco node for indexMenu
[73] => Created Aco node for search
[74] => Created Aco node for count
[75] => Created Aco node for autoComplete
[76] => Created Aco node for add
[77] => Created Aco node for afterAdd
[78] => Created Aco node for view
[79] => Created Aco node for afterView
[80] => Created Aco node for edit
[81] => Created Aco node for afterEdit
[82] => Created Aco node for delete
[83] => Created Aco node for GlobalLocations
[84] => Created Aco node for blackHole
[85] => Created Aco node for isSuperuser
[86] => Created Aco node for indexFind
[87] => Created Aco node for index
[88] => Created Aco node for indexMenu
[89] => Created Aco node for search
[90] => Created Aco node for count
[91] => Created Aco node for autoComplete
[92] => Created Aco node for add
[93] => Created Aco node for afterAdd
[94] => Created Aco node for view
[95] => Created Aco node for afterView
[96] => Created Aco node for edit
[97] => Created Aco node for afterEdit
[98] => Created Aco node for delete
[99] => Created Aco node for Groups
[100] => Created Aco node for afterAdd
[101] => Created Aco node for afterEdit
[102] => Created Aco node for index
[103] => Created Aco node for build_acl
[104] => Created Aco node for blackHole
[105] => Created Aco node for isSuperuser
[106] => Created Aco node for indexFind
[107] => Created Aco node for indexMenu
[108] => Created Aco node for search
[109] => Created Aco node for count
[110] => Created Aco node for autoComplete
[111] => Created Aco node for add
[112] => Created Aco node for view
[113] => Created Aco node for afterView
[114] => Created Aco node for edit
[115] => 

Re: Validation and Form Helper

2010-11-05 Thread MissYeh
Yes. you will have to manually set in the view to limit the max
characters that you can enter in a field.

Cake doesn't do this automatically for the front end. The validation
rules are for the server end.


On Nov 5, 8:19 am, chris  wrote:
> Thanks for the reply.
>
> They are text fields in the database, but then I am limiting them by
> the validation rules, so looks like I will have to manually set the
> limits in the view.
>
> On Nov 4, 5:39 pm, euromark  wrote:
>
> > as of now, yes
> > maxlength is determined by the database schema (varchar(36) => 36
> > chars)
> > but i am sure this can be achieved somehow :)
>
> > On 4 Nov., 16:54, chris  wrote:
>
> > > Just getting used to setting validation rules in CakePHP.
>
> > > I notice that the form helper will automatically mark a field if it is
> > > set as required.
>
> > > Is there a way to make the form helper change the size of a input box,
> > > and restrict the number of characters that can be entered, based on
> > > validation rules?
>
> > > I have this sort of thing in the model
>
> > > 'maxlength' => array(
> > >                                 'rule'=> array('maxlength',30),
> > >                                 'message' => 'Name can only be 30 
> > > characters long'
> > >                         )
>
> > > But this does not seem to affect the form controls.
>
> > > Am I asking to much of the form helper?

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: Named parameters, forms and redirects

2010-11-05 Thread chris
Thanks for your reply and suggestions, I have adjusted my code since
and it seems to be working fine, will look at these options as well
and see how I can improve it.

At least it dosn't sound like I am doing something completely wrong.

On Nov 4, 10:05 pm, WebbedIT  wrote:
> As I suspected, the issue is when you initially request the form you
> are passing it in via $_GET as a named parameter, then when you submit
> the form you change to passing it in via $_POST into the model's data
> array instead.
>
> I actually do it this way myself and have my method specified as
> something like
>
> function add($foreign_id = null) {
>   $foreign_id = $data['Model']['foreign_id'] ? $data['Model']
> ['foreign_id'] : $foreign_id;
>   if (!$foreign_id) {
>     // error
>   }
>
> }
>
> You could move this logic to the controllers isAuthorized() method to
> throw an auth error
>
> function isAuthorized() {
>   switch ($this->action) {
>     case 'add':
>       $foreign_id = $this->data['Model']['foreign_id'] ? $data['Model']
> ['foreign_id'] : $this->params['named']['foreign_id'];
>       if (!$foreign_id) return false;
>       break;
>   }
>   return true;
>
> }
>
> but I think this is wrong as the existence of a foreign_id is not
> really an Auth issue.  The other method would be to  amend $form-
>
> >create in your view so the form submits to '/model/add/foreign_id:1'
>
> No hard and fast answer really.
>
> HTH, Paul.

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


Ensuring uniqueness on application level

2010-11-05 Thread Éber
Hey guys!

I'm having a little bit of trouble with validation on my models. That
is because I'm using isUnique on some fields, but I didn't defined the
fields as unique keys on the DB (I'm using MySQL). I can't make them
unique keys right now because I'm using soft deletion on these models.

The thing is that, sometimes the DB connection will break, and
isUnique won't return a valid value, making it possible for my users
to register things with the same name, which is causing a lot of
trouble for me. I was trying to think in a way to ensure that, even
when the DB fails, I get some sort of good value from isUnique, so the
user won't be able to register with a duplicated name...

Does anyone have any hints on how can I do this the best way possible?

Thanks!

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: Is there a standard way of making sure that foreign keys exist?

2010-11-05 Thread Joshua Muheim
It's done. :-)

orphansProtectableOptions = array_merge(array(
), $settings);
  }

  /**
   * ???
   */
  function beforeValidate(&$Model) {
$valid = true;
foreach($Model->belongsTo as $model => $settings) {
  $foreignKey = $settings['foreignKey'];
  $foreignKeyValue = $Model->data[$Model->name][$foreignKey];
  if(!empty($foreignKeyValue)) {
$Model->{$model}->id = $foreignKeyValue;
if(!$Model->{$model}->exists()) {
  $Model->invalidate($foreignKey, sprintf(__('ID %s does not
exist', true), $foreignKeyValue));
  $valid = false;
}
  }
}
return $valid;
  }
}
?>

Maybe I will upload this to my SVN and add a blog post for it, soon...

On Thu, Nov 4, 2010 at 9:51 PM, cricket  wrote:
> On Thu, Nov 4, 2010 at 5:57 AM, psybear83  wrote:
>> Hi everybody
>>
>> Before creating a behavior myself I wanted to ask this (see title).
>>
>> I only found this:
>> http://ask.cakephp.org/questions/view/how_to_check_the_validness_of_a_foreign-key_must_contained_in_primary-key_list
>>
>> ...but there's no solution for the problem.
>>
>> If nothing like this exists yet, I will create a behavior on my own
>> and will be happy to share it with the community. Just don't want to
>> do work that's already been done.
>
> It should be straightforward to create a custom validation method.I've
> never considered using a behavior for validation but I think it could
> be done in principle.
>
> 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
>

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: Validation and Form Helper

2010-11-05 Thread chris
Thanks for the reply.

They are text fields in the database, but then I am limiting them by
the validation rules, so looks like I will have to manually set the
limits in the view.


On Nov 4, 5:39 pm, euromark  wrote:
> as of now, yes
> maxlength is determined by the database schema (varchar(36) => 36
> chars)
> but i am sure this can be achieved somehow :)
>
> On 4 Nov., 16:54, chris  wrote:
>
> > Just getting used to setting validation rules in CakePHP.
>
> > I notice that the form helper will automatically mark a field if it is
> > set as required.
>
> > Is there a way to make the form helper change the size of a input box,
> > and restrict the number of characters that can be entered, based on
> > validation rules?
>
> > I have this sort of thing in the model
>
> > 'maxlength' => array(
> >                                 'rule'=> array('maxlength',30),
> >                                 'message' => 'Name can only be 30 
> > characters long'
> >                         )
>
> > But this does not seem to affect the form controls.
>
> > Am I asking to much of the form helper?

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


ActiveRecord getting resource instead of dataset

2010-11-05 Thread Adrian Arnautu
Hello to everyone,

Is there a way to get a resource and then fetch a row at a time from it
instead of getting the whole rows in one structure?
For a small dataset it's relatively fine, but when this dataset is growing
(for example, you want to generate a CSV having ~ 5-6k rows or maybe more)
it looks overkilling in terms of memory requirements.

I know that the possible answer is somewhere in the source code, I want to
know if any of you used this approach.

Thank you,
Adrian

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


Client specific translations?

2010-11-05 Thread Henrik Gemal
I need to have client specific translations in a project of mine.

The project is already translated into 2 languages "eng" and "dan".

The project serves different clients.

Now a client of my wants to have a different translations for some
strings.

I'm thinking about implementing like this:

First if we are to use "eng" we try:
- look in "eng" client specific translation for the string (locale/eng/
LC_MESSAGES/client_id.pod)
- if not found there look in generic "eng" translation file (locale/
eng/LC_MESSAGES/default.pod)

How would I implement this in CakePHP 1.3.5 ?

Any pointers?

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