3.0 Tree Behavior - understanding find('treeList')

2014-07-11 Thread Michael Houghton
I am using the 3.0 Tree Behavior.

I have the following from the docs:

$pages = $this-Pages-find('treeList');

http://book.cakephp.org/3.0/en/core-libraries/behaviors/tree.html

This just doesn't feel right.  It isn't returning a list at all.  Should I 
be doing something else, like:

$pages = $this-Pages-find('treeList')-all();

It just feels like I am missing something here.

When I put my $pages variable into my 'options' = $pages for my form 
select, I get the following error:

*Error: * Function name must be a string 
*File* 
/home/michael/public_html/bettornet/vendor/cakephp/cakephp/src/Collection/Iterator/TreePrinter.php
 

*Line: * 77

Any help with this would be appreciated.

Thanks in advance.
Michael

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: 3.0 Tree Behavior - understanding find('treeList')

2014-07-11 Thread José Lorenzo
Not sure what you mean with  It isn't returning a list at all. Can you 
explain?

On Friday, July 11, 2014 9:47:27 AM UTC+2, Michael Houghton wrote:

 I am using the 3.0 Tree Behavior.

 I have the following from the docs:

 $pages = $this-Pages-find('treeList');

 http://book.cakephp.org/3.0/en/core-libraries/behaviors/tree.html

 This just doesn't feel right.  It isn't returning a list at all.  Should I 
 be doing something else, like:

 $pages = $this-Pages-find('treeList')-all();

 It just feels like I am missing something here.

 When I put my $pages variable into my 'options' = $pages for my form 
 select, I get the following error:

 *Error: * Function name must be a string 
 *File* 
 /home/michael/public_html/bettornet/vendor/cakephp/cakephp/src/Collection/Iterator/TreePrinter.php
  

 *Line: * 77

 Any help with this would be appreciated.

 Thanks in advance.
 Michael


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: 3.0 Tree Behavior - understanding find('treeList')

2014-07-11 Thread Michael Houghton
Hey Jose

Sure thing.  This seems like a similar issue that I had with:

$this-Models-findByField($name)-first();

If you recall, I missed the - first() and was trying:

$this-Models-findByField($name);

Which just gives a whole lot of data on the schema.

With the tree behavior, I am calling:

$pages = $this-Pages-find('treeList');
pr($pages); die;

But again, it is giving me a lot of schema stuff.  I checked the docs, but 
it only mentions what I did - how to a build the list here - in 2.x we 
would do:

$this-Page-generateTreeList();

I want to build the same list in 3.0!

Do you have any idea what I could be missing?

Thanks again for your help - I am slowly getting my head around this!

On Friday, July 11, 2014 9:18:08 AM UTC+1, José Lorenzo wrote:

 Not sure what you mean with  It isn't returning a list at all. Can you 
 explain?



-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: 3.0 Tree Behavior - understanding find('treeList')

2014-07-11 Thread José Lorenzo
All find() methods returns a query object. All query objects have a first() 
and toArray() method. If you want to see the results of your find you can 
do:

$pages = $this-Pages-find('treeList')-toArray();

On Friday, July 11, 2014 10:28:58 AM UTC+2, Michael Houghton wrote:

 Hey Jose

 Sure thing.  This seems like a similar issue that I had with:

 $this-Models-findByField($name)-first();

 If you recall, I missed the - first() and was trying:

 $this-Models-findByField($name);

 Which just gives a whole lot of data on the schema.

 With the tree behavior, I am calling:

 $pages = $this-Pages-find('treeList');
 pr($pages); die;

 But again, it is giving me a lot of schema stuff.  I checked the docs, but 
 it only mentions what I did - how to a build the list here - in 2.x we 
 would do:

 $this-Page-generateTreeList();

 I want to build the same list in 3.0!

 Do you have any idea what I could be missing?

 Thanks again for your help - I am slowly getting my head around this!

 On Friday, July 11, 2014 9:18:08 AM UTC+1, José Lorenzo wrote:

 Not sure what you mean with  It isn't returning a list at all. Can you 
 explain?



-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: 3.0 Tree Behavior - understanding find('treeList')

2014-07-11 Thread Michael Houghton
Thanks Jose - that seems to be it! It might be worth updating the Tree docs 
to show this.

Unfortunately, that is still giving me the error:

*Error: * Function name must be a string 
*File* 
/home/michael/public_html/bettornet/vendor/cakephp/cakephp/src/Collection/Iterator/TreePrinter.php
 


Any idea what this could be?

Thanks again.

On Friday, July 11, 2014 10:24:30 AM UTC+1, José Lorenzo wrote:

 All find() methods returns a query object. All query objects have a 
 first() and toArray() method. If you want to see the results of your find 
 you can do:

 $pages = $this-Pages-find('treeList')-toArray();




-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: 3.0 Tree Behavior - understanding find('treeList')

2014-07-11 Thread José Lorenzo
Can you gist your full code, I have no idea what that error is.

On Friday, July 11, 2014 11:49:40 AM UTC+2, Michael Houghton wrote:

 Thanks Jose - that seems to be it! It might be worth updating the Tree 
 docs to show this.

 Unfortunately, that is still giving me the error:

 *Error: * Function name must be a string 
 *File* 
 /home/michael/public_html/bettornet/vendor/cakephp/cakephp/src/Collection/Iterator/TreePrinter.php
  


 Any idea what this could be?

 Thanks again.

 On Friday, July 11, 2014 10:24:30 AM UTC+1, José Lorenzo wrote:

 All find() methods returns a query object. All query objects have a 
 first() and toArray() method. If you want to see the results of your find 
 you can do:

 $pages = $this-Pages-find('treeList')-toArray();




-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: 3.0 Tree Behavior - understanding find('treeList')

2014-07-11 Thread Michael Houghton
Hey Jose

Here it is:
https://gist.github.com/cakecoded/59511a440dfb9c5c7628

On Friday, July 11, 2014 12:44:56 PM UTC+1, José Lorenzo wrote:

 Can you gist your full code, I have no idea what that error is.

 On Friday, July 11, 2014 11:49:40 AM UTC+2, Michael Houghton wrote:

 Thanks Jose - that seems to be it! It might be worth updating the Tree 
 docs to show this.

 Unfortunately, that is still giving me the error:

 *Error: * Function name must be a string 
 *File* 
 /home/michael/public_html/bettornet/vendor/cakephp/cakephp/src/Collection/Iterator/TreePrinter.php
  


 Any idea what this could be?

 Thanks again.

 On Friday, July 11, 2014 10:24:30 AM UTC+1, José Lorenzo wrote:

 All find() methods returns a query object. All query objects have a 
 first() and toArray() method. If you want to see the results of your find 
 you can do:

 $pages = $this-Pages-find('treeList')-toArray();




-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: 3.0 Tree Behavior - understanding find('treeList')

2014-07-11 Thread José Lorenzo
I cannot reproduce this issue. What PHP version do you have? Can you paste 
the the contents of the line where it is throwing the fatal error?

On Friday, July 11, 2014 2:28:11 PM UTC+2, Michael Houghton wrote:

 Hey Jose

 Here it is:
 https://gist.github.com/cakecoded/59511a440dfb9c5c7628

 On Friday, July 11, 2014 12:44:56 PM UTC+1, José Lorenzo wrote:

 Can you gist your full code, I have no idea what that error is.

 On Friday, July 11, 2014 11:49:40 AM UTC+2, Michael Houghton wrote:

 Thanks Jose - that seems to be it! It might be worth updating the Tree 
 docs to show this.

 Unfortunately, that is still giving me the error:

 *Error: * Function name must be a string 
 *File* 
 /home/michael/public_html/bettornet/vendor/cakephp/cakephp/src/Collection/Iterator/TreePrinter.php
  


 Any idea what this could be?

 Thanks again.

 On Friday, July 11, 2014 10:24:30 AM UTC+1, José Lorenzo wrote:

 All find() methods returns a query object. All query objects have a 
 first() and toArray() method. If you want to see the results of your find 
 you can do:

 $pages = $this-Pages-find('treeList')-toArray();




-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Understanding MVC Architecture

2012-04-24 Thread lowpass
I think there are no hard and fast rules for this. I've done that in
the past where it seems to make sense to list the associated model
data from a particular controller. If all you want to do is list the
Members of a given Organization -- and not provide links to do
anything further with a given Member -- then it might be fine to put
the action in OrganizationsController. However, I'll generally create
a controller for the other model(s), if only for admin functions. In
your case, you may have a need for an admin to create a new
OrganizationRole, for example.

On Sun, Apr 22, 2012 at 12:45 PM, bs28723
bill.sto...@boosterwebsolutions.com wrote:
 My question is - Is it a better MVC architecture to have a 1 to 1
 relationship for a controller to access the model and the view, or since
 in a case where all relationships stem from a single model - just make
 the one controller have all the actions, but pull data from the related
 models needed together to then send to a view.

 Here is some code to help illustrate what I am talking about. ( I
 removed a lot of configuration details, because it is not relevant for
 the architecture discussion)

 Organization Model
      $hasMany = array('OrganizationRole', 'Address', 'MemberRelationship');
      $belongsTo = array('User');

 OrganizationRole Model
      $hasMany = array('OrganizationPermission', 'MemberRelationship');
      $belongsTo = array('Organization');

 MemberRelationship Model
      $belongsTo = array('Organization', 'User', 'MembershipLevel',
 'OrganizationRole');

 OrganizationPermission Model
     $belongsTo = array('OrganizationRole');

 User Model
      $hasMany = array('Organization', 'MemberRelationship', 'Address');


 So, as you can see, everything is related to Organization either
 directly or indirectly.  So, I am thinking of adding actions to
 OrganizationsController to do things like viewMembers, editMembers,
 deleteMembers, viewRoles, editRoles, assignRoles, etc
 rather than putting calling view, edit, delete actions in
 MemberRelationshipsController and OrganizationRolesControllers.

 Any thoughts? Opinions? Suggestions?

 Thanks,
 Bill

 
 View this message in context: Understanding MVC Architecture
 Sent from the CakePHP mailing list archive at Nabble.com.

 --
 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

-- 
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: Understanding MVC Architecture

2012-04-24 Thread bs28723
Thanks for the reply.  It just seems like I am putting 100 functions in 
the one controller and a 100 views in the one folder. Just managing the 
code and the single file could get complicated.
But from a user experience, they are managing the organization. These 
are just areas to manage.
So, maybe my question should be...

What is a better way to manage the code?  Maybe I should create 
components to manage the code related to a Model?

On 4/24/2012 3:08 PM, lowpass [via CakePHP] wrote:
 I think there are no hard and fast rules for this. I've done that in
 the past where it seems to make sense to list the associated model
 data from a particular controller. If all you want to do is list the
 Members of a given Organization -- and not provide links to do
 anything further with a given Member -- then it might be fine to put
 the action in OrganizationsController. However, I'll generally create
 a controller for the other model(s), if only for admin functions. In
 your case, you may have a need for an admin to create a new
 OrganizationRole, for example.

 On Sun, Apr 22, 2012 at 12:45 PM, bs28723
 [hidden email] /user/SendEmail.jtp?type=nodenode=5663027i=0 wrote:

  My question is - Is it a better MVC architecture to have a 1 to 1
  relationship for a controller to access the model and the view, or 
 since
  in a case where all relationships stem from a single model - just make
  the one controller have all the actions, but pull data from the related
  models needed together to then send to a view.
 
  Here is some code to help illustrate what I am talking about. ( I
  removed a lot of configuration details, because it is not relevant for
  the architecture discussion)
 
  Organization Model
   $hasMany = array('OrganizationRole', 'Address', 
 'MemberRelationship');
   $belongsTo = array('User');
 
  OrganizationRole Model
   $hasMany = array('OrganizationPermission', 'MemberRelationship');
   $belongsTo = array('Organization');
 
  MemberRelationship Model
   $belongsTo = array('Organization', 'User', 'MembershipLevel',
  'OrganizationRole');
 
  OrganizationPermission Model
  $belongsTo = array('OrganizationRole');
 
  User Model
   $hasMany = array('Organization', 'MemberRelationship', 'Address');
 
 
  So, as you can see, everything is related to Organization either
  directly or indirectly.  So, I am thinking of adding actions to
  OrganizationsController to do things like viewMembers, editMembers,
  deleteMembers, viewRoles, editRoles, assignRoles, etc
  rather than putting calling view, edit, delete actions in
  MemberRelationshipsController and OrganizationRolesControllers.
 
  Any thoughts? Opinions? Suggestions?
 
  Thanks,
  Bill
 
  
  View this message in context: Understanding MVC Architecture
  Sent from the CakePHP mailing list archive at Nabble.com.
 
  --
  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
  [hidden email] /user/SendEmail.jtp?type=nodenode=5663027i=1 For 
 more options, visit this group at
  http://groups.google.com/group/cake-php

 -- 
 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
 [hidden email] /user/SendEmail.jtp?type=nodenode=5663027i=2 For 
 more options, visit this group at http://groups.google.com/group/cake-php


 
 If you reply to this email, your message will be added to the 
 discussion below:
 http://cakephp.1045679.n5.nabble.com/Understanding-MVC-Architecture-tp5657637p5663027.html
  

 To start a new topic under CakePHP, email 
 ml-node+s1045679n125572...@n5.nabble.com
 To unsubscribe from CakePHP, click here 
 http://cakephp.1045679.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=1255722code=YmlsbC5zdG9sdHpAYm9vc3RlcndlYnNvbHV0aW9ucy5jb218MTI1NTcyMnwtNTU0NTk2MTUy.
 NAML 
 http://cakephp.1045679.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml
  



--
View this message in context: 
http://cakephp.1045679.n5.nabble.com/Understanding-MVC-Architecture-tp5657637p5663601.html
Sent from the CakePHP mailing list archive at Nabble.com.

-- 
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

Re: Understanding MVC Architecture

2012-04-24 Thread lowpass
On Tue, Apr 24, 2012 at 8:12 PM, bs28723
bill.sto...@boosterwebsolutions.com wrote:
 Thanks for the reply.  It just seems like I am putting 100 functions in the
 one controller and a 100 views in the one folder. Just managing the code and
 the single file could get complicated.

Then you should probably be breaking things up a bit.

Also, keep in mind that it's always better to put as much code into
your models rather than the controllers. You can always call its
methods by $this-Model1-Model2-doSomething() if they're associated.

 But from a user experience, they are managing the organization. These are
 just areas to manage.

Yet in some case, you'll be managing a specific Member. There
shouldn't really be any need to do so from the
OrganizationsController. For listing all of the Members within an Org,
sure. But then to edit one of them, you can go to the
MembersController. Once saved, redirect back to the
OrganizationsController.

Router::connect(
'/admin/orgs/:id',
array(
'admin' = 1,
'controller' = 'organizations',
'action' = 'view'
),
array('id' = '[0-9]+', 'pass' = array('id'))
);

public function admin_view($id = null)
{
// pull data for some org
}

Router::connect(
'/admin/orgs/:id/members',
array(
'admin' = 1,
'controller' = 'organizations',
'action' = 'members'
),
array('id' = '[0-9]+', 'pass' = array('id'))
);

public function admin_members($id = null)
{
// pull data for some org and list members
}

When you list the members, create a link pointing to the MembersController:

foreach($data['Member'] as $member) {
$this-Html-link(
$member['name'],
array(
'admin' = 1,
'controller' = 'members',
'action' = 'edit',
'id' = $member['id']
),
array('title' = 'edit this member')
);
}


Router::connect(
'/admin/members/edit/:id',
array(
'admin' = 1,
'controller' = 'members',
'action' = 'edit'
),
array('id' = '[0-9]+', 'pass' = array('id'))
);

public function admin_edit($id = null)
{
// validate and save ...

// redirect back to org's member list
$route = array(
'admin' = 1,
'controller' = 'organizations',
'action' = 'members',
'id' = $this-request-data['Member']['organization_id']
);
$this-redirect($route);
}

 So, maybe my question should be...

 What is a better way to manage the code?  Maybe I should create components
 to manage the code related to a Model?

No, don't do that. If you start creating components to handle
model-specific tasks then you'd definitely be going in the wrong
direction.

Also, it's difficult to tell by just seeing the model names and not
the entire schema, but my hunch is that you might be able to normalize
things so that you have fewer models overall. But that really depends
on what exactly you need to do.

-- 
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: Understanding MVC Architecture

2012-04-24 Thread bs28723
Great ideas. I will see about pushing more into the models.  I have not 
really done much with the router, but that gives me some ideas on how I 
can do some things.

The data is fairly normalized, I am sure there is room for improvement. 
But it needs to scale.
Basic premise is Users manage their profile, and can do a few things.  
Users can create organizations. The User/Owner of the Organization can 
manage it.  Users can join Organizations.   Users can join multiple 
organizations and have different roles.
If you are familiar with facebook groups then this concept is part of my 
site.  I an not trying to recreate facebook or anything like that, but 
some of the features of signup, moderation or manage the group, are a 
good analogy. The main point is that it has to scale and that there are 
several many to many tables.

Which brings up another question - I had some challenges getting the 
multiple roles and ACL working. So, I have basically used Controller 
based authorization and isAuthorized routines. This works well.  The 
documentation talks about you could go to a model based authorization.  
I assume it works the same, except that the isAuthorized routines will 
be in the Models instead of the controllers.  I can't seem to find a lot 
of examples of why to do this?  I don't know if this would be a good 
idea or not.  Do you have any ideas or thoughts about this?

Thanks again for the help.


--
View this message in context: 
http://cakephp.1045679.n5.nabble.com/Understanding-MVC-Architecture-tp5657637p5663744.html
Sent from the CakePHP mailing list archive at Nabble.com.

-- 
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: Understanding MVC Architecture

2012-04-24 Thread bs28723
))
 $this-loadModel('MemberRelationship');
 $ret = 
$this-MemberRelationship-addRelationship($user, $orgId, 
$role['OrganizationRole']['id']);
 }
 if ($ret) {
 $this-Session-setFlash(__('The organization 
has been saved'));
 } else {
 $this-Session-setFlash(__('The User / 
organization relationship could not be saved. Please, try again.'));
 }
 }

 $this-redirect(array('action' = 'view', 
$this-Organization-id));
 } else {
 $this-Session-setFlash(__('The organization could not 
be saved. Please, try again.'));
 }
 }

 }



--
View this message in context: 
http://cakephp.1045679.n5.nabble.com/Understanding-MVC-Architecture-tp5657637p5663807.html
Sent from the CakePHP mailing list archive at Nabble.com.

-- 
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


Understanding MVC Architecture

2012-04-22 Thread bs28723
My question is - Is it a better MVC architecture to have a 1 to 1 
relationship for a controller to access the model and the view, or since 
in a case where all relationships stem from a single model - just make 
the one controller have all the actions, but pull data from the related 
models needed together to then send to a view.

Here is some code to help illustrate what I am talking about. ( I 
removed a lot of configuration details, because it is not relevant for 
the architecture discussion)

Organization Model
 $hasMany = array('OrganizationRole', 'Address', 'MemberRelationship');
 $belongsTo = array('User');

OrganizationRole Model
 $hasMany = array('OrganizationPermission', 'MemberRelationship');
 $belongsTo = array('Organization');

MemberRelationship Model
 $belongsTo = array('Organization', 'User', 'MembershipLevel', 
'OrganizationRole');

OrganizationPermission Model
$belongsTo = array('OrganizationRole');

User Model
 $hasMany = array('Organization', 'MemberRelationship', 'Address');


So, as you can see, everything is related to Organization either 
directly or indirectly.  So, I am thinking of adding actions to 
OrganizationsController to do things like viewMembers, editMembers, 
deleteMembers, viewRoles, editRoles, assignRoles, etc
rather than putting calling view, edit, delete actions in 
MemberRelationshipsController and OrganizationRolesControllers.

Any thoughts? Opinions? Suggestions?

Thanks,
Bill


--
View this message in context: 
http://cakephp.1045679.n5.nabble.com/Understanding-MVC-Architecture-tp5657637p5657637.html
Sent from the CakePHP mailing list archive at Nabble.com.

-- 
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: Help Understanding Fat Models

2012-01-31 Thread Marius
Great explaniation Jeremy! +1

I recently got my head around the principle too. I'd recomend it
included in the cookbook alongside MVC introduction to reinforce the
DRY concept. Essential learning for more complex systems.

On Jan 30, 9:52 pm, jeremyharris funeralm...@gmail.com wrote:
 The best advice is to keep things DRY (Don't Repeat Yourself). Generally,
 this results in thin controllers (small controller functions) and fat
 models (more methods on the models). Any functionality that you will find
 yourself reusing across different controllers that appropriately relate to
 a model should be on that model, instead.

 As an example (typical blog example).

 //posts_controller
 function edit($id) {
 // check if user is the creator of this post and is therefore allowed to
 edit
 $post = $this-Post-read(null, $id);
 if (empty($post) || $post['Post']['created_by'] != $this-Auth-user('id'))
 {
 //redirect
 return;

 }
 }

 function delete($id) {
 // check if user has rights to delete
 $post = $this-Post-read(null, $id);
 if (empty($post) || $post['Post']['created_by'] != $this-Auth-user('id'))
 {
 //redirect
 return;

 }
 }

 Your controller would be considered fat because you duplicated code and
 this is logic that belongs in the model. Instead, something like this looks
 better:

 // post model
 function userOwnsPost($userId, $postId) {
 return $this-hasAny(array(
 'id' = $postId,
 'created_by' = $userId
 ));

 }

 // posts controller
 function edit($id) {
 if (!$this-Post-userOwnsPost($this-Auth-user('id'), $id)) {
 //redirect

 }
 }

 function delete($id) {
 if (!$this-Post-userOwnsPost($this-Auth-user('id'), $id)) {
 //redirect

 }
 }

 Perhaps not the *best* example, but you get the idea. This code is also
 much easier to test. If you ever change the behavior of userOwnsPost, it
 will change across the app. It's also very specific, which makes writing
 tests really easy.

 If you find yourself writing long, complex find conditions and using them
 over and over again, they probably belong in model. Remember, many small
 functions are easier to test and predict the outcome than large functions.

 Another example might be finding a list of posts that belong to a tag. You
 would place this in your Post or Tag model, and might call it in
 /posts/index, /pages/home, /posts/view,
 /users/posts_in_tags_i_have_created, etc.

 For small apps, it may not be necessary to move these functions around!
 But, I'd say the more you have in models the better, even if only for
 testing's sake. It's easier to find out what went wrong when your methods
 are smaller and very specific. Controller methods are usually less specific
 than model methods.

 Hope that clears it up a bit.

-- 
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


Help Understanding Fat Models

2012-01-30 Thread Chooch Schubert
I see the oft-repeated phrase Keep your controllers thin and models fat,
but I'm having a problem wrapping my head around it. Most of the tutorials
and examples I see have just about all of the code in the controllers, and
the models have little more than associations.

So.. what exactly does a fat model look like? How do I know what to pull
out of my controllers to move into models - everything seems to be working
great the way it is. Do methods/actions/functions look and work the same in
a model as they do in a controller?


Any advice, pointers, links are much appreciated!

  {c}

-- 
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: Help Understanding Fat Models

2012-01-30 Thread jeremyharris
The best advice is to keep things DRY (Don't Repeat Yourself). Generally, 
this results in thin controllers (small controller functions) and fat 
models (more methods on the models). Any functionality that you will find 
yourself reusing across different controllers that appropriately relate to 
a model should be on that model, instead.

As an example (typical blog example).

//posts_controller
function edit($id) {
// check if user is the creator of this post and is therefore allowed to 
edit
$post = $this-Post-read(null, $id);
if (empty($post) || $post['Post']['created_by'] != $this-Auth-user('id')) 
{
//redirect
return;
}
}

function delete($id) {
// check if user has rights to delete
$post = $this-Post-read(null, $id);
if (empty($post) || $post['Post']['created_by'] != $this-Auth-user('id')) 
{
//redirect
return;
}
}

Your controller would be considered fat because you duplicated code and 
this is logic that belongs in the model. Instead, something like this looks 
better:

// post model
function userOwnsPost($userId, $postId) {
return $this-hasAny(array(
'id' = $postId,
'created_by' = $userId
));
}

// posts controller
function edit($id) {
if (!$this-Post-userOwnsPost($this-Auth-user('id'), $id)) {
//redirect
}
}

function delete($id) {
if (!$this-Post-userOwnsPost($this-Auth-user('id'), $id)) {
//redirect
}
}

Perhaps not the *best* example, but you get the idea. This code is also 
much easier to test. If you ever change the behavior of userOwnsPost, it 
will change across the app. It's also very specific, which makes writing 
tests really easy.

If you find yourself writing long, complex find conditions and using them 
over and over again, they probably belong in model. Remember, many small 
functions are easier to test and predict the outcome than large functions.

Another example might be finding a list of posts that belong to a tag. You 
would place this in your Post or Tag model, and might call it in 
/posts/index, /pages/home, /posts/view, 
/users/posts_in_tags_i_have_created, etc.

For small apps, it may not be necessary to move these functions around! 
But, I'd say the more you have in models the better, even if only for 
testing's sake. It's easier to find out what went wrong when your methods 
are smaller and very specific. Controller methods are usually less specific 
than model methods.

Hope that clears it up a bit.

-- 
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: Help Understanding Fat Models

2012-01-30 Thread Chooch Schubert
Thank you Jeremy. This is a great, concise description and the example code
helps a lot to see the difference.

 {c}


On Mon, Jan 30, 2012 at 4:52 PM, jeremyharris funeralm...@gmail.com wrote:

 The best advice is to keep things DRY (Don't Repeat Yourself). Generally,
 this results in thin controllers (small controller functions) and fat
 models (more methods on the models). Any functionality that you will find
 yourself reusing across different controllers that appropriately relate to
 a model should be on that model, instead.

 As an example (typical blog example).

 //posts_controller
 function edit($id) {
 // check if user is the creator of this post and is therefore allowed to
 edit
 $post = $this-Post-read(null, $id);
 if (empty($post) || $post['Post']['created_by'] !=
 $this-Auth-user('id')) {
 //redirect
 return;
 }
 }

 function delete($id) {
 // check if user has rights to delete
 $post = $this-Post-read(null, $id);
 if (empty($post) || $post['Post']['created_by'] !=
 $this-Auth-user('id')) {
 //redirect
 return;
 }
 }

 Your controller would be considered fat because you duplicated code and
 this is logic that belongs in the model. Instead, something like this looks
 better:

 // post model
 function userOwnsPost($userId, $postId) {
 return $this-hasAny(array(
 'id' = $postId,
 'created_by' = $userId
 ));
 }

 // posts controller
 function edit($id) {
 if (!$this-Post-userOwnsPost($this-Auth-user('id'), $id)) {
 //redirect
 }
 }

 function delete($id) {
 if (!$this-Post-userOwnsPost($this-Auth-user('id'), $id)) {
 //redirect
 }
 }

 Perhaps not the *best* example, but you get the idea. This code is also
 much easier to test. If you ever change the behavior of userOwnsPost, it
 will change across the app. It's also very specific, which makes writing
 tests really easy.

 If you find yourself writing long, complex find conditions and using them
 over and over again, they probably belong in model. Remember, many small
 functions are easier to test and predict the outcome than large functions.

 Another example might be finding a list of posts that belong to a tag. You
 would place this in your Post or Tag model, and might call it in
 /posts/index, /pages/home, /posts/view,
 /users/posts_in_tags_i_have_created, etc.

 For small apps, it may not be necessary to move these functions around!
 But, I'd say the more you have in models the better, even if only for
 testing's sake. It's easier to find out what went wrong when your methods
 are smaller and very specific. Controller methods are usually less specific
 than model methods.

 Hope that clears it up a bit.

 --
 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


-- 
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: Help Understanding Fat Models

2012-01-30 Thread jeremyharris
Cool, glad it helped. There are other examples around the internet too.

-- 
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: Haveing a basic understanding problem regarding media views

2011-05-05 Thread dreamingmind
heidi,

The message seems pretty clear, the folder you're requesting does not
exist. But what's wrong with your request. It's a bit mysterious
because your code looks like sample values and the message looks like
a real message. The path named in the message doesn't remotely look
like something you'd get when running your code.

You'd expect '/DTAfiles/something.something  was onto found on the
server'. So, where is this 'members/download' path coming from? You
could search your code or data tables to figure out what is creating
the path 'members/download/...'

I can see one error in your code though. Your 'path' parameter should
not have the file name stuck on the end of it. See the examples:
http://book.cakephp.org/view/1094/Media-Views

Regards,
Don

On May 4, 1:25 am, heohni heidi.anselstet...@consultingteam.de
wrote:
 hi,

 I have an action to create a txt file and write stuff into.
 Then I redirect to another action, where I have a simple template with
 a download button.
 On click, I would like to download the txt file, the name of the file
 I pass within the url to the download function.

 function download(){
         $this-view = 'Media';
         $params = array(
               'id' = $this-params['named']['do'].'.txt',
               'name' = 'example',
               'extension' = 'txt',
               'mimeType' = array('txt' = 'text/plain'),   // extends
 internal list of mimeTypes
               'path' = WWW_ROOT.'/DTAfiles/'.$this-params['named']
 ['do'].'.txt'
        );
        $this-set($params);

 }

 But I get the message
 Not Found
 Error: The requested address '/members/download/040520111017' was not
 found on this server.

 I dont understand why this isn't working, what do I do wrong?

-- 
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


Haveing a basic understanding problem regarding media views

2011-05-04 Thread heohni
hi,

I have an action to create a txt file and write stuff into.
Then I redirect to another action, where I have a simple template with
a download button.
On click, I would like to download the txt file, the name of the file
I pass within the url to the download function.

function download(){
$this-view = 'Media';
$params = array(
  'id' = $this-params['named']['do'].'.txt',
  'name' = 'example',
  'extension' = 'txt',
  'mimeType' = array('txt' = 'text/plain'),   // extends
internal list of mimeTypes
  'path' = WWW_ROOT.'/DTAfiles/'.$this-params['named']
['do'].'.txt'
   );
   $this-set($params);
}

But I get the message
Not Found
Error: The requested address '/members/download/040520111017' was not
found on this server.

I dont understand why this isn't working, what do I do wrong?

-- 
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


i'm not understanding the 2nd parameter in postConditions

2011-03-24 Thread varai
Hi,

I'm new to cakePHP and OOP.

The code below is from 
http://book.cakephp.org/view/875/x1-3-Collection#!/view/977/Controller-Methods.
Can someone please explain the postConditons below? I don't understand
how can num_items key contain '=' and referrer key contain 'LIKE'.
What does the word compact in find('all', compact('condtions')) mean?
Thank you.

/*
Contents of $this-data
array(
'Order' = array(
'num_items' = '4',
'referrer' = 'Ye Olde'
)
)
*/

//Let’s get orders that have at least 4 items and contain ‘Ye Olde’
$condtions=$this-postConditions(
$this-data,
array(
'num_items' = '=',
'referrer' = 'LIKE'
)
);
$orders = $this-Order-find(all,compact('condtions'));

-- 
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: i'm not understanding the 2nd parameter in postConditions

2011-03-24 Thread cricket
On Thu, Mar 24, 2011 at 6:24 AM, varai vaanip...@gmail.com wrote:
 Hi,

 I'm new to cakePHP and OOP.

 The code below is from 
 http://book.cakephp.org/view/875/x1-3-Collection#!/view/977/Controller-Methods.
 Can someone please explain the postConditons below? I don't understand
 how can num_items key contain '=' and referrer key contain 'LIKE'.
 What does the word compact in find('all', compact('condtions')) mean?
 Thank you.

 /*
 Contents of $this-data
 array(
    'Order' = array(
        'num_items' = '4',
        'referrer' = 'Ye Olde'
    )
 )
 */

 //Let’s get orders that have at least 4 items and contain ‘Ye Olde’
 $condtions=$this-postConditions(
    $this-data,
    array(
        'num_items' = '=',
        'referrer' = 'LIKE'
    )
 );
 $orders = $this-Order-find(all,compact('condtions'));

I think the best thing you could do, as a new Cake user, is to pretend
you never saw this method. It's is a little-known shortcut that
requires a pretty good understanding of how Cake operates.

That said, what the method does is apply the values from the 2nd param
array to the find conditions so as to change the query. The above
example would be equivalent to:

$this-Order-find(
'all',
array(
'conditions' = array(
'num_items =' = '4',
'referrer LIKE' = 'Ye Olde'
)
)
)

And compact() is another convenience:
http://php.net/manual/en/function.compact.php

-- 
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


Understanding Models

2011-03-18 Thread varai
Hi

I'm new to cakePHP and OOP.

I'm not understanding
1)what find('all') in the following code means
2) what is the purpose of  $this-set('ingredients', $ingredients);
 I got this from book.cakephp.org.

?php
class IngredientsController extends AppController {
function index() {
//grab all ingredients and pass it to the view:
$ingredients = $this-Ingredient-find('all');
$this-set('ingredients', $ingredients);
}
}

?

any help is much appreciated

-- 
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: Understanding Models

2011-03-18 Thread Ryan Schmidt

On Mar 18, 2011, at 04:24, varai wrote:

 I'm new to cakePHP and OOP.
 
 I'm not understanding
 1)what find('all') in the following code means

find('all') finds all records in this model's database table and returns them 
to you as an array.

 2) what is the purpose of  $this-set('ingredients', $ingredients);

This sets the variable 'ingredients' (in the view) to the value of the variable 
$ingredients (here in this controller method), so that you can display it in 
the view.

 I got this from book.cakephp.org.
 
 ?php
 class IngredientsController extends AppController {
function index() {
//grab all ingredients and pass it to the view:
$ingredients = $this-Ingredient-find('all');
$this-set('ingredients', $ingredients);
}
 }
 
 ?

Spend some more time reading the book and looking at example CakePHP projects. 
Hopefully it will become clear to you how it all works together.




-- 
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: Understanding the M in MVC?

2011-02-04 Thread Jeremy Burns | Class Outfit
Shell scripts are beyond my experience, so can't contribute to that one. Sounds 
like this ought to go in a component though, if you want to do it from multiple 
controllers.

Jeremy Burns
Class Outfit

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

On 4 Feb 2011, at 07:45, Ryan Schmidt wrote:

 
 On Feb 4, 2011, at 01:13, Jeremy Burns | Class Outfit wrote:
 
 Create a function in your controller that firstly creates the connection 
 object. Then have the function get the data from the model, which returns an 
 array to the controller and is stored in a variable in the controller. Now 
 parse that array running your controller/component function against your 
 connection object.
 
 I thought that might be the answer... but what if I not only need to do this 
 from a controller (multiple controllers), but also from shell scripts (in 
 APP/vendor/shells)?
 
 
 -- 
 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

-- 
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: Understanding the M in MVC?

2011-02-04 Thread AD7six


On Feb 3, 3:12 pm, Michael Carriere m...@zapdot.com wrote:
 Hello everyone!

 When recently approached to do some web development for a game whose code 
 base was in dire need of a rewrite, I was determined on finding a stable, 
 community supported framework to help speed up the process. I appreciate 
 Cake's file organization, the way layouts are controlled, among other things, 
 but I seem to be having a difficult time in the way I should be understanding 
 the M in MVC. I've done enough web development in the past to be familiar 
 with PHP, but more recently I've worked in object-oriented, compiled 
 languages, as well as a few web tools built with Django. I could just give up 
 and do whatever works, but I feel like there's something powerful to be 
 taken advantage of here, and I hope you guys can help!

 How magical is the find() function?

As magical as you want it to be - or not as the case may be.

 Should I be able to run one exhaustive query and get back all the nested data 
 that I need for a View to spit out?

you should be able to call whatever model method you want from a
controller and pass it to the view, yes.

 I guess a better question would be: do you find yourself calling find() on 
 different sets of data, packaging them together yourself (presumably with the 
 Set class, right?) and then passing that to the view to be displayed?

That's my personal preference.

ie. example controller code:

$posts = $this-Post-find('all', compact('conditions'));
$uids = Set::extract($posts, '/Post/user_id');
$authors = $this-Post-User-find('list', array('conditions' =
array('id' = $uids));
$this-set(compact('posts', 'authors'));


 I have some data that is loosely related, and while I can manage to get at 
 all of it in one query, it requires me using Containable, and dropping 5-6 
 associations in. That just seems quite inefficient for me. (Maybe it's not?)

containable has its uses, decide based on the sql it generates.


 Coming from many OO languages, after you define a class, you instantiate it 
 as you want to work with an individual object, play with it as you want, and 
 throw it out. Correct me if I'm wrong, but it seems that MVC's approach is 
 more geared towards operating on all the data at once?

don't know what you mean.

 Or at least in the case of working with a Model.

 This leads to some confusion for me, because the majority of the instances 
 where I need to access data, it's of a small subset of the data I'm storing 
 in the DB for my model. My webgame has Buildings in it, which belong to a 
 User's Village. Sometimes I want to grab information from a specific 
 Building, and other times I want to grab only the specific Buildings of a 
 Village. Is it proper to be define a function within the model that grabs or 
 manipulates data based on this, like 
 $this-Village-getBuildingsByVillageId()?

why would you create an alias for existing simple find calls?

 Better yet, how do you operate on 'instances' of your data as defined by your 
 model?

instances of your data are arrays - you treat them as arrays.


 I may have some more questions later, but I'll start this thread with these 
 two (albeit loaded) questions.

try and keep it to one question per thread and you're more likely to
get answers that help.

AD

-- 
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: Understanding the M in MVC?

2011-02-04 Thread AD7six


On Feb 4, 8:13 am, Jeremy Burns | Class Outfit
jeremybu...@classoutfit.com wrote:
 Create a function in your controller that firstly creates the connection 
 object.

Holy MVC sacrilege batman. I hope you meant to say model.

$stuff = $this-Model-somefunction()

is about as far as a controller should go

AD

-- 
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: Understanding the M in MVC?

2011-02-04 Thread AD7six


On Feb 4, 8:45 am, Ryan Schmidt google-2...@ryandesign.com wrote:
 On Feb 4, 2011, at 01:13, Jeremy Burns | Class Outfit wrote:

  Create a function in your controller that firstly creates the connection 
  object. Then have the function get the data from the model, which returns 
  an array to the controller and is stored in a variable in the controller. 
  Now parse that array running your controller/component function against 
  your connection object.

 I thought that might be the answer... but what if I not only need to do this 
 from a controller (multiple controllers), but also from shell scripts (in 
 APP/vendor/shells)?

Fat models dictate that only models should eat datasources, and
controllers and shells should only feed models params

AD

-- 
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: Understanding the M in MVC?

2011-02-04 Thread Jeremy Burns | Class Outfit
I take your point, and I'll admit that my controllers are often too fat. I call 
model functions as much as possible, but find myself dipping back into the 
controller when I need to use the Auth component, the Session, redirect and so 
on (although I do collect as much info as I can and pass it into the model 
function when possible). Am I alone in that?

What is the principle behind fat model/skinny controller; is it performance, 
efficiency, code cleanliness?

Jeremy Burns
Class Outfit

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

On 4 Feb 2011, at 09:09, AD7six wrote:

 
 
 On Feb 4, 8:13 am, Jeremy Burns | Class Outfit
 jeremybu...@classoutfit.com wrote:
 Create a function in your controller that firstly creates the connection 
 object.
 
 Holy MVC sacrilege batman. I hope you meant to say model.
 
 $stuff = $this-Model-somefunction()
 
 is about as far as a controller should go
 
 AD
 
 -- 
 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

-- 
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: Understanding the M in MVC?

2011-02-04 Thread AD7six


On Feb 4, 10:29 am, Jeremy Burns | Class Outfit
jeremybu...@classoutfit.com wrote:
 I take your point, and I'll admit that my controllers are often too fat. I 
 call model functions as much as possible, but find myself dipping back into 
 the controller when I need to use the Auth component, the Session, redirect 
 and so on (although I do collect as much info as I can and pass it into the 
 model function when possible). Am I alone in that?

 What is the principle behind fat model/skinny controller; is it performance, 
 efficiency, code cleanliness?

Consider writing some functionality in your controller and /then/
needing it in a shell such as Ryan's situation. If you use models as
intended it's trivial to solve, if not you've got the pending question
how do I use that controller from this shell? which is a question
that shouldn't ever exist.

It's the same problem/question if you need the same functionality in
two or more controllers, but there you're likely to either cheat and
use requestAction or worse needless inheritance/a component. Neither
of which help with the shell conundrum which imo is quite common as a
project scales and you find you need to do more and more things via
shell scripts.

AD

-- 
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


Understanding the M in MVC?

2011-02-03 Thread Michael Carriere
Hello everyone!

When recently approached to do some web development for a game whose code base 
was in dire need of a rewrite, I was determined on finding a stable, community 
supported framework to help speed up the process. I appreciate Cake's file 
organization, the way layouts are controlled, among other things, but I seem to 
be having a difficult time in the way I should be understanding the M in MVC. 
I've done enough web development in the past to be familiar with PHP, but more 
recently I've worked in object-oriented, compiled languages, as well as a few 
web tools built with Django. I could just give up and do whatever works, but 
I feel like there's something powerful to be taken advantage of here, and I 
hope you guys can help!


How magical is the find() function? Should I be able to run one exhaustive 
query and get back all the nested data that I need for a View to spit out? I 
guess a better question would be: do you find yourself calling find() on 
different sets of data, packaging them together yourself (presumably with the 
Set class, right?) and then passing that to the view to be displayed?

I have some data that is loosely related, and while I can manage to get at all 
of it in one query, it requires me using Containable, and dropping 5-6 
associations in. That just seems quite inefficient for me. (Maybe it's not?)

Coming from many OO languages, after you define a class, you instantiate it as 
you want to work with an individual object, play with it as you want, and throw 
it out. Correct me if I'm wrong, but it seems that MVC's approach is more 
geared towards operating on all the data at once? Or at least in the case of 
working with a Model.

This leads to some confusion for me, because the majority of the instances 
where I need to access data, it's of a small subset of the data I'm storing in 
the DB for my model. My webgame has Buildings in it, which belong to a User's 
Village. Sometimes I want to grab information from a specific Building, and 
other times I want to grab only the specific Buildings of a Village. Is it 
proper to be define a function within the model that grabs or manipulates data 
based on this, like $this-Village-getBuildingsByVillageId()? Better yet, how 
do you operate on 'instances' of your data as defined by your model?

I may have some more questions later, but I'll start this thread with these two 
(albeit loaded) questions.

Any help is appreciated, thank you!

- Michael


-- 
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: Understanding the M in MVC?

2011-02-03 Thread andy_the ultimate baker
will u please make it short and approachable to ur point,
becouse no one is having to read a long theses of ur query on the
work
so please make it shor and come in pints, so it would be fine to give
u answer

regards
andy

On Feb 3, 7:12 pm, Michael Carriere m...@zapdot.com wrote:
 Hello everyone!

 When recently approached to do some web development for a game whose code 
 base was in dire need of a rewrite, I was determined on finding a stable, 
 community supported framework to help speed up the process. I appreciate 
 Cake's file organization, the way layouts are controlled, among other things, 
 but I seem to be having a difficult time in the way I should be understanding 
 the M in MVC. I've done enough web development in the past to be familiar 
 with PHP, but more recently I've worked in object-oriented, compiled 
 languages, as well as a few web tools built with Django. I could just give up 
 and do whatever works, but I feel like there's something powerful to be 
 taken advantage of here, and I hope you guys can help!

 How magical is the find() function? Should I be able to run one exhaustive 
 query and get back all the nested data that I need for a View to spit out? I 
 guess a better question would be: do you find yourself calling find() on 
 different sets of data, packaging them together yourself (presumably with the 
 Set class, right?) and then passing that to the view to be displayed?

 I have some data that is loosely related, and while I can manage to get at 
 all of it in one query, it requires me using Containable, and dropping 5-6 
 associations in. That just seems quite inefficient for me. (Maybe it's not?)

 Coming from many OO languages, after you define a class, you instantiate it 
 as you want to work with an individual object, play with it as you want, and 
 throw it out. Correct me if I'm wrong, but it seems that MVC's approach is 
 more geared towards operating on all the data at once? Or at least in the 
 case of working with a Model.

 This leads to some confusion for me, because the majority of the instances 
 where I need to access data, it's of a small subset of the data I'm storing 
 in the DB for my model. My webgame has Buildings in it, which belong to a 
 User's Village. Sometimes I want to grab information from a specific 
 Building, and other times I want to grab only the specific Buildings of a 
 Village. Is it proper to be define a function within the model that grabs or 
 manipulates data based on this, like 
 $this-Village-getBuildingsByVillageId()? Better yet, how do you operate on 
 'instances' of your data as defined by your model?

 I may have some more questions later, but I'll start this thread with these 
 two (albeit loaded) questions.

 Any help is appreciated, thank you!

 - Michael

-- 
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: Understanding the M in MVC?

2011-02-03 Thread ibejohn818
Model-View-Controller

Model is data.

Cakephp's model layer uses a programming technique called ORM (Object-
Relational-Mapping)
http://en.wikipedia.org/wiki/Object-relational_mapping

If you are familiar with python then it would be comparable to
sqlalchemy but just not as many features and configuration options.

On Feb 3, 6:12 am, Michael Carriere m...@zapdot.com wrote:
 Hello everyone!

 When recently approached to do some web development for a game whose code 
 base was in dire need of a rewrite, I was determined on finding a stable, 
 community supported framework to help speed up the process. I appreciate 
 Cake's file organization, the way layouts are controlled, among other things, 
 but I seem to be having a difficult time in the way I should be understanding 
 the M in MVC. I've done enough web development in the past to be familiar 
 with PHP, but more recently I've worked in object-oriented, compiled 
 languages, as well as a few web tools built with Django. I could just give up 
 and do whatever works, but I feel like there's something powerful to be 
 taken advantage of here, and I hope you guys can help!

 How magical is the find() function? Should I be able to run one exhaustive 
 query and get back all the nested data that I need for a View to spit out? I 
 guess a better question would be: do you find yourself calling find() on 
 different sets of data, packaging them together yourself (presumably with the 
 Set class, right?) and then passing that to the view to be displayed?

 I have some data that is loosely related, and while I can manage to get at 
 all of it in one query, it requires me using Containable, and dropping 5-6 
 associations in. That just seems quite inefficient for me. (Maybe it's not?)

 Coming from many OO languages, after you define a class, you instantiate it 
 as you want to work with an individual object, play with it as you want, and 
 throw it out. Correct me if I'm wrong, but it seems that MVC's approach is 
 more geared towards operating on all the data at once? Or at least in the 
 case of working with a Model.

 This leads to some confusion for me, because the majority of the instances 
 where I need to access data, it's of a small subset of the data I'm storing 
 in the DB for my model. My webgame has Buildings in it, which belong to a 
 User's Village. Sometimes I want to grab information from a specific 
 Building, and other times I want to grab only the specific Buildings of a 
 Village. Is it proper to be define a function within the model that grabs or 
 manipulates data based on this, like 
 $this-Village-getBuildingsByVillageId()? Better yet, how do you operate on 
 'instances' of your data as defined by your model?

 I may have some more questions later, but I'll start this thread with these 
 two (albeit loaded) questions.

 Any help is appreciated, thank you!

 - Michael

-- 
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: Understanding the M in MVC?

2011-02-03 Thread Jeremy Burns | Class Outfit
Michael

I find the model structure very flexible. I generally set recursive to -1 (this 
means my starting point is this record and none of its associations), and use 
the Containable behaviour; both of these are set in my custom app_model.php 
file, which means they apply to all models by default.

Before even touching a model I thrash out my actual data model as best as I can 
and then build my models around it starting with the associations and 
validation first. I like to make my data tightly integrated so that I can rely 
on relationships, but there are always occasions when a bit of data just 
doesn't link with another, but I know I am going to have to tie them together. 
I also build some generic find queries that I know I will use many times - 
these tend to be fully featured containing all the key related data for a given 
'id'. Saves me building the same query over and over again and it's easier to 
maintain.

When something doesn't fit I and I need to tie unrelated data together (which 
is rare) I do one of three things:
- Store the unrelated data in the session, if it's small and appropriate, or 
even in a config file.
- Use loadModel to make it available to 'this' controller, perform a find and 
store the result in an array for later manipulation = perhaps in the model.
- Use the 'joins' elements to construct my own query (I prefer this to using 
'query'). I also fall back on this method if I want to restrict a record set by 
a condition on one of its relationships using inner joins (Contain uses outer 
joins).

When models are associated correctly you can indeed daisy chain across them to 
call an action on a distant model.

Not sure that totally answers your question, but I hope it gets the ball 
rolling.

Jeremy Burns
Class Outfit

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

On 4 Feb 2011, at 05:02, andy_the ultimate baker wrote:

 will u please make it short and approachable to ur point,
 becouse no one is having to read a long theses of ur query on the
 work
 so please make it shor and come in pints, so it would be fine to give
 u answer
 
 regards
 andy
 
 On Feb 3, 7:12 pm, Michael Carriere m...@zapdot.com wrote:
 Hello everyone!
 
 When recently approached to do some web development for a game whose code 
 base was in dire need of a rewrite, I was determined on finding a stable, 
 community supported framework to help speed up the process. I appreciate 
 Cake's file organization, the way layouts are controlled, among other 
 things, but I seem to be having a difficult time in the way I should be 
 understanding the M in MVC. I've done enough web development in the past 
 to be familiar with PHP, but more recently I've worked in object-oriented, 
 compiled languages, as well as a few web tools built with Django. I could 
 just give up and do whatever works, but I feel like there's something 
 powerful to be taken advantage of here, and I hope you guys can help!
 
 How magical is the find() function? Should I be able to run one exhaustive 
 query and get back all the nested data that I need for a View to spit out? I 
 guess a better question would be: do you find yourself calling find() on 
 different sets of data, packaging them together yourself (presumably with 
 the Set class, right?) and then passing that to the view to be displayed?
 
 I have some data that is loosely related, and while I can manage to get at 
 all of it in one query, it requires me using Containable, and dropping 5-6 
 associations in. That just seems quite inefficient for me. (Maybe it's not?)
 
 Coming from many OO languages, after you define a class, you instantiate it 
 as you want to work with an individual object, play with it as you want, and 
 throw it out. Correct me if I'm wrong, but it seems that MVC's approach is 
 more geared towards operating on all the data at once? Or at least in the 
 case of working with a Model.
 
 This leads to some confusion for me, because the majority of the instances 
 where I need to access data, it's of a small subset of the data I'm storing 
 in the DB for my model. My webgame has Buildings in it, which belong to a 
 User's Village. Sometimes I want to grab information from a specific 
 Building, and other times I want to grab only the specific Buildings of a 
 Village. Is it proper to be define a function within the model that grabs or 
 manipulates data based on this, like 
 $this-Village-getBuildingsByVillageId()? Better yet, how do you operate on 
 'instances' of your data as defined by your model?
 
 I may have some more questions later, but I'll start this thread with these 
 two (albeit loaded) questions.
 
 Any help is appreciated, thank you!
 
 - Michael
 
 -- 
 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

Re: Understanding the M in MVC?

2011-02-03 Thread Ryan Schmidt
Welcome!


On Feb 3, 2011, at 08:12, Michael Carriere wrote:

   • How magical is the find() function? Should I be able to run one 
 exhaustive query and get back all the nested data that I need for a View to 
 spit out? I guess a better question would be: do you find yourself calling 
 find() on different sets of data, packaging them together yourself 
 (presumably with the Set class, right?) and then passing that to the view to 
 be displayed?
 
 I have some data that is loosely related, and while I can manage to get at 
 all of it in one query, it requires me using Containable, and dropping 5-6 
 associations in. That just seems quite inefficient for me. (Maybe it's not?)

Based on what i've read, Containable seems like the best answer to your 
question. Without Containable, you can specify a recursion level, but that's 
it. Much better to use Containable to say exactly which items from which levels 
you want to receive, and it figures out the rest.


   • Coming from many OO languages, after you define a class, you 
 instantiate it as you want to work with an individual object, play with it as 
 you want, and throw it out. Correct me if I'm wrong, but it seems that MVC's 
 approach is more geared towards operating on all the data at once? Or at 
 least in the case of working with a Model.
 
 This leads to some confusion for me, because the majority of the instances 
 where I need to access data, it's of a small subset of the data I'm storing 
 in the DB for my model. My webgame has Buildings in it, which belong to a 
 User's Village. Sometimes I want to grab information from a specific 
 Building, and other times I want to grab only the specific Buildings of a 
 Village. Is it proper to be define a function within the model that grabs or 
 manipulates data based on this, like 
 $this-Village-getBuildingsByVillageId()? Better yet, how do you operate on 
 'instances' of your data as defined by your model?

I have questions along these lines too.

It seems to me that the Model is there to let you access your data, usually 
from a database table (though it doesn't have to be). So a Model does not 
represent an instance of something from your database table*; rather, it is an 
interface to retrieve data from it -- be that a single record or a set of 
records, and possibly, depending on recursion or Containable, related records. 
This data is usually returned by the find() method, and is in the form of a 
rather nested array. You receive the array from the Model (in your Controller, 
or in a Shell perhaps), loop over the records, and do whatever you want with 
them.

Yes, it seems correct to define additional methods in your Model that return 
data from particular queries that are of use to you. It seems to me that if 
your method is getBuildingsByVillageId(), then it would be in the Building 
model (because it primarily returns information about Buildings), not in the 
Village model, though I'm not clear what the guidance is on this topic.

*This is complicated by the fact that in some cases you can get data from a 
particular row to live in the Model -- to be the active record -- and you can 
page through all the records in your data set this way. I'm not certain yet 
whether this is just an alternate way to access the same data that's just more 
comfortable to some people, or whether there are cases when this is the only 
way to do it.

It's still unclear to me what the best way is to, for example, define 
additional variables that go with a particular record. My first impulse was to 
define an instance variable in the Model, but in light of the above, that 
doesn't seem correct.




-- 
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: Understanding the M in MVC?

2011-02-03 Thread Sam Sherlock
M = Model
Interaction with data  stored in a database or via a datasource (eg the
twitter example)

Dropping assocs on the fly is easier than building them on the fly
You set the associations as they would generally be needed between models
within your app

Your setting you app up to be able to retrive exactly what you require with
the least amount of controller and view coding
setting up models in the right way (associations, behaviours, validation,
custom find methods) means you can use and reuse
these models in versatile ways within your app

a lean app with fat models;

that custom model method really depends on the complexity of the find you
are using; if you can then additionally make it serve other purposes
elsewhere - eg pass it params to have it return data for different
circumstances

and what Jeremy says :)
and now Ryan has also answered

@ryan - the right thing takes some working out

A user
 name (full and secondname -- 2 fields)
 username to login
 hasMany published recipe's (table)
 hasMany favorite recipe's ()

A recipee will have
 One title (which is made into a slug)
 One slug (an auto field)
 hasMany-ingredients (table)
 belongs to user

Ingredients
  Name



- S



On 4 February 2011 05:02, andy_the ultimate baker 
anandghaywankar...@gmail.com wrote:

 will u please make it short and approachable to ur point,
 becouse no one is having to read a long theses of ur query on the
 work
 so please make it shor and come in pints, so it would be fine to give
 u answer

 regards
 andy

 On Feb 3, 7:12 pm, Michael Carriere m...@zapdot.com wrote:
  Hello everyone!
 
  When recently approached to do some web development for a game whose code
 base was in dire need of a rewrite, I was determined on finding a stable,
 community supported framework to help speed up the process. I appreciate
 Cake's file organization, the way layouts are controlled, among other
 things, but I seem to be having a difficult time in the way I should be
 understanding the M in MVC. I've done enough web development in the past
 to be familiar with PHP, but more recently I've worked in object-oriented,
 compiled languages, as well as a few web tools built with Django. I could
 just give up and do whatever works, but I feel like there's something
 powerful to be taken advantage of here, and I hope you guys can help!
 
  How magical is the find() function? Should I be able to run one
 exhaustive query and get back all the nested data that I need for a View to
 spit out? I guess a better question would be: do you find yourself calling
 find() on different sets of data, packaging them together yourself
 (presumably with the Set class, right?) and then passing that to the view to
 be displayed?
 
  I have some data that is loosely related, and while I can manage to get
 at all of it in one query, it requires me using Containable, and dropping
 5-6 associations in. That just seems quite inefficient for me. (Maybe it's
 not?)
 
  Coming from many OO languages, after you define a class, you instantiate
 it as you want to work with an individual object, play with it as you want,
 and throw it out. Correct me if I'm wrong, but it seems that MVC's approach
 is more geared towards operating on all the data at once? Or at least in the
 case of working with a Model.
 
  This leads to some confusion for me, because the majority of the
 instances where I need to access data, it's of a small subset of the data
 I'm storing in the DB for my model. My webgame has Buildings in it, which
 belong to a User's Village. Sometimes I want to grab information from a
 specific Building, and other times I want to grab only the specific
 Buildings of a Village. Is it proper to be define a function within the
 model that grabs or manipulates data based on this, like
 $this-Village-getBuildingsByVillageId()? Better yet, how do you operate on
 'instances' of your data as defined by your model?
 
  I may have some more questions later, but I'll start this thread with
 these two (albeit loaded) questions.
 
  Any help is appreciated, thank you!
 
  - Michael

 --
 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.comcake-php%2bunsubscr...@googlegroups.comFor
  more options, visit this group at
 http://groups.google.com/group/cake-php


-- 
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: Understanding the M in MVC?

2011-02-03 Thread Ryan Schmidt

On Feb 3, 2011, at 23:36, Sam Sherlock wrote:

 On Feb 3, 2011, at 23:22, Ryan Schmidt wrote:
 
 It's still unclear to me what the best way is to, for example, define 
 additional variables that go with a particular record. My first impulse was 
 to define an instance variable in the Model, but in light of the above, that 
 doesn't seem correct.
 
 @ryan - the right thing takes some working out
 
 A user 
  name (full and secondname -- 2 fields)
  username to login
  hasMany published recipe's (table)
  hasMany favorite recipe's ()
 
 A recipee will have 
  One title (which is made into a slug)
  One slug (an auto field)
  hasMany-ingredients (table)
  belongs to user

I understand that much; I'm not having any troubles defining columns in my 
database tables. What I am having trouble with is where to store variables that 
relate to their rows.

For example, perhaps I have a table of hostnames and a Hostname model. I have a 
method that will find() some subset of them. Then I would like to connect to 
each of them using some network protocol. There is an object (not a model; just 
a PHP class loaded from the libs directory) that represents that connection. 
Where should I be storing that object? There will be multiple operations 
performed over that single connection once it's opened, so I would dislike to 
have to create the network connection anew in each method; that would be 
inefficient and wasteful of network resources. It shouldn't be the 
responsibility of a controller or a shell script to create this connection 
object; it's directly related to the Hostname model so it should be in that 
model. If the model were an object representing a hostname instance, then I 
might have had a private $_connection instance variable, and a public method 
getConnection(), which creates $this-_connection if it hasn't already been 
created (i.e. instantiates the connection object, which opens the network 
connection) and returns it. But since the model is merely a way to get an array 
of data, I'm unsure what technique I should be using.



-- 
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: Understanding the M in MVC?

2011-02-03 Thread Jeremy Burns | Class Outfit
Create a function in your controller that firstly creates the connection 
object. Then have the function get the data from the model, which returns an 
array to the controller and is stored in a variable in the controller. Now 
parse that array running your controller/component function against your 
connection object.

Jeremy Burns
Class Outfit

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

On 4 Feb 2011, at 07:06, Ryan Schmidt wrote:

 
 On Feb 3, 2011, at 23:36, Sam Sherlock wrote:
 
 On Feb 3, 2011, at 23:22, Ryan Schmidt wrote:
 
 It's still unclear to me what the best way is to, for example, define 
 additional variables that go with a particular record. My first impulse was 
 to define an instance variable in the Model, but in light of the above, 
 that doesn't seem correct.
 
 @ryan - the right thing takes some working out
 
 A user 
 name (full and secondname -- 2 fields)
 username to login
 hasMany published recipe's (table)
 hasMany favorite recipe's ()
 
 A recipee will have 
 One title (which is made into a slug)
 One slug (an auto field)
 hasMany-ingredients (table)
 belongs to user
 
 I understand that much; I'm not having any troubles defining columns in my 
 database tables. What I am having trouble with is where to store variables 
 that relate to their rows.
 
 For example, perhaps I have a table of hostnames and a Hostname model. I have 
 a method that will find() some subset of them. Then I would like to connect 
 to each of them using some network protocol. There is an object (not a model; 
 just a PHP class loaded from the libs directory) that represents that 
 connection. Where should I be storing that object? There will be multiple 
 operations performed over that single connection once it's opened, so I would 
 dislike to have to create the network connection anew in each method; that 
 would be inefficient and wasteful of network resources. It shouldn't be the 
 responsibility of a controller or a shell script to create this connection 
 object; it's directly related to the Hostname model so it should be in that 
 model. If the model were an object representing a hostname instance, then I 
 might have had a private $_connection instance variable, and a public method 
 getConnection(), which creates $this-_connection if it hasn't already been 
 created (i.e. instantiates the connection object, which opens the network 
 connection) and returns it. But since the model is merely a way to get an 
 array of data, I'm unsure what technique I should be using.
 
 
 
 -- 
 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

-- 
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: Understanding the M in MVC?

2011-02-03 Thread Ryan Schmidt

On Feb 4, 2011, at 01:13, Jeremy Burns | Class Outfit wrote:

 Create a function in your controller that firstly creates the connection 
 object. Then have the function get the data from the model, which returns an 
 array to the controller and is stored in a variable in the controller. Now 
 parse that array running your controller/component function against your 
 connection object.

I thought that might be the answer... but what if I not only need to do this 
from a controller (multiple controllers), but also from shell scripts (in 
APP/vendor/shells)?


-- 
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


Listing 23 24. Validate the username (problem understanding at all)

2010-12-11 Thread John Maxim
Taking validation further
(TUTORIAL)
Sometimes you can't tell if data is valid just by looking at it. For
example, the username may be between six and 40 characters, but you
will have to check the database to see if the username is already
taken. CakePHP provides the ability to manually mark a field as
invalid. Take a look at the beforeValidate method in Listing 23. This
method would be added to the user model.

Listing 23. Validate the username


 function beforeValidate() {
if (!$this-id) {
if ($this-findCount(array('User.username'
= $this-data['User']['username']))  0) {
$this-invalidate('username_unique');
return false;
}
}
return true;
}


+QUESTIONER++
So we need to put this in user model ? but currently there isn't any
function in it.. how do I add it in ?

Before posting for help here, I have tried adding in and it all went
wrong. Now I would like to find out where exactly to add this and is
this the phpcake 3.1 version's script ? I noticed many scripts were
deprecated and I have to keep checking on the comments.

My current user model script is as follow:

?php

class User extends AppModel
{
var $name = 'User';

var $validate = array (
'username' = array ('rule' = '/^.{6,40}$/'),

'password' = array('rule'='/^.{6,40}$/'),

'email' = array(
'notEmpty' = array(
'rule' = 'notEmpty',
'message' = 'This field cannot be blank',
'last' = true
),
'email' = array(
'rule' = 'email',
'message' = 'That is not a valid email
address'
)
)

);

}

?

(TUTORIAL CONTINUE)
Is Listing 24 compulsory ? :

You can take full advantage of this by changing the username input
line in the register.ctp view to the following.

Listing 24. New username input line

 echo $form-input('username', array('after' = $form-error
   ('username_unique', 'The username is taken. Please try
again.')));

+++QUESTIONER+++
I really have no idea what this can do, lost. I have put both Listing
23  24 in but it gave a list of 4-5 errors



Any help please, 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: having trouble understanding associations

2010-03-29 Thread Gianluca
Johnny,

if you need any help, just drop me a line and I'll try to get back to
you asap.

Cheers,
Gian.


On 26 Mar, 21:44, Johnny Ferguson hyperfle...@gmail.com wrote:
 It's a little difficult to wrap my head around, but I think I see
 what's going on.

 belongsTo is a many to one relation, so many PracticeInstance belong
 to 1 PracticeItem

 That defies my intuition, because it's more natural for me to think of
 a PracticeItem as belonging to a PracticeSession. The PracticeSession
 has a PracticeItem.

 I'll work through developing this app, and see if my understanding
 doesn't grow a little. Thanks, Gian.

 On Mar 26, 3:17 pm, Gianluca gc1...@googlemail.com wrote:



  Hello Johnny,

  class PracticeItem extends AppModel {

  }

  class PracticeInstance extends AppModel {
     var $belongsTo = 'PracticeItem';

  }

  class PracticeSession extends AppModel {
    var $hasMany = 'PracticeInstance';

  }

  tblPracticeInstances
  * id
  * practiceitem_id
  * practicesession_id
  * 

  tblPracticeSessions
  * id
  * 

  Let me know if you need more.

  Cheers,
  Gian.

  On 26 Mar, 18:57, Johnny Ferguson hyperfle...@gmail.com wrote:

   Looking 
   here:http://book.cakephp.org/view/78/Associations-Linking-Models-Together

   I'm certain my issue is due to a personal lack of understanding.

   I'm trying to homebrew a simple app to keep track of my guitar
   practice.

   I have the following models:
   PracticeItem: a specific exercise to be practiced any number of times
   PracticeInstance: an instance of having practiced one specific
   PracticeItem
   PracticeSession: a collection of PracticeInstance

   My immediate instinct is to say PracticeInstance hasOne
   PracticeItem.

   According to the Book: X hasOne Y = table Y having an X_id field.

   In my case PracticeInstance hasOne PracticeItem would mean:
   PracticeItems has a field practice_instance_id

   This makes no sense because if I were to create a PracticeItem called
   Major Scales 2, I would plan to practice it multiple times.

   If the field for this PracticeItem looks like
   id = 123
   title = Major Scales 2
   practice_instance_id = 23

   then I would have to duplicate the PracticeItem every time I practiced
   it.

   To me it would make more sense if PracticeInstance looked like:
   id  = primaryKey, autoincrement
   datetime = ...
   comment = ...
   timeSpent = ...
   practice_item_id = 123

   Can anyone explain where I might have mixed things up?

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: Help understanding containable

2010-03-28 Thread WebbedIT
Containable works by running lots of queries and then merging the data
into a cake-like array for you.  As such you cannot throw in
conditions on deeply associated models and expect it to limit the
results.  You need to force joins so you can specify the conditions
you want.

To limit the amount of ad-hoc joins you will have to make I would run
this find on the Bill model as that is directly related to Account and
BillResource.  However, we need to change the Bill hasMany
BillResource to Bill hasOne BillResource, so it runs one query using
all 3 tables, using unbindModel and bindModel.

If running this from the Client controller, add the following to the
relevant action:

$this-Client-Account-Bill-
unbindModel(array('hasMany'=array('BillResource')));
$this-Client-Account-Bill-
bindModel(array('hasOne'=array('BillResource')));
$this-Client-Account-Bill-find('all', array(
  'conditions'=array(
'Account.client_id'=$client_id,
'BillResource.resource_type_id'=$resource_type_id
  ),
  'contain'=array(
'Account'=array('Client'),
'BillResource'=array('ResourceType')
  )
));

If paginating this data add a false parameter to the unbind and bind
calls as follows (makes the change last the whole http request rather
than just one find call):

$this-Client-Account-Bill-
unbindModel(array('hasMany'=array('BillResource')), false);
$this-Client-Account-Bill-
bindModel(array('hasOne'=array('BillResource')), false);

I have not tested any of this, so apologies for any typos!

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: having trouble understanding associations

2010-03-27 Thread WebbedIT
The easy rule of thumb with belongsTo is if your table has a
foreignKey it belongsTo the model that key refers to.

Your only decision then is to choose whether the other side of the
association is a hasOne or hasMany.

Also whilst on the subject of understanding associations, it's worth
noting that hasAndBelongsToMany is simply a convenience wrapper for

- Model1 hasMany JoinModel
- JoinModel belongsTo Model1
- JoinModel belongsTo Model2
- Model2 hasMany JoinModel

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


having trouble understanding associations

2010-03-26 Thread Johnny Ferguson
Looking here:
http://book.cakephp.org/view/78/Associations-Linking-Models-Together

I'm certain my issue is due to a personal lack of understanding.

I'm trying to homebrew a simple app to keep track of my guitar
practice.

I have the following models:
PracticeItem: a specific exercise to be practiced any number of times
PracticeInstance: an instance of having practiced one specific
PracticeItem
PracticeSession: a collection of PracticeInstance

My immediate instinct is to say PracticeInstance hasOne
PracticeItem.

According to the Book: X hasOne Y = table Y having an X_id field.

In my case PracticeInstance hasOne PracticeItem would mean:
PracticeItems has a field practice_instance_id

This makes no sense because if I were to create a PracticeItem called
Major Scales 2, I would plan to practice it multiple times.

If the field for this PracticeItem looks like
id = 123
title = Major Scales 2
practice_instance_id = 23

then I would have to duplicate the PracticeItem every time I practiced
it.

To me it would make more sense if PracticeInstance looked like:
id  = primaryKey, autoincrement
datetime = ...
comment = ...
timeSpent = ...
practice_item_id = 123

Can anyone explain where I might have mixed things up?

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: having trouble understanding associations

2010-03-26 Thread Gianluca
Hello Johnny,

class PracticeItem extends AppModel {
}

class PracticeInstance extends AppModel {
   var $belongsTo = 'PracticeItem';
}

class PracticeSession extends AppModel {
  var $hasMany = 'PracticeInstance';
}

tblPracticeInstances
* id
* practiceitem_id
* practicesession_id
* 

tblPracticeSessions
* id
* 

Let me know if you need more.

Cheers,
Gian.

On 26 Mar, 18:57, Johnny Ferguson hyperfle...@gmail.com wrote:
 Looking 
 here:http://book.cakephp.org/view/78/Associations-Linking-Models-Together

 I'm certain my issue is due to a personal lack of understanding.

 I'm trying to homebrew a simple app to keep track of my guitar
 practice.

 I have the following models:
 PracticeItem: a specific exercise to be practiced any number of times
 PracticeInstance: an instance of having practiced one specific
 PracticeItem
 PracticeSession: a collection of PracticeInstance

 My immediate instinct is to say PracticeInstance hasOne
 PracticeItem.

 According to the Book: X hasOne Y = table Y having an X_id field.

 In my case PracticeInstance hasOne PracticeItem would mean:
 PracticeItems has a field practice_instance_id

 This makes no sense because if I were to create a PracticeItem called
 Major Scales 2, I would plan to practice it multiple times.

 If the field for this PracticeItem looks like
 id = 123
 title = Major Scales 2
 practice_instance_id = 23

 then I would have to duplicate the PracticeItem every time I practiced
 it.

 To me it would make more sense if PracticeInstance looked like:
 id  = primaryKey, autoincrement
 datetime = ...
 comment = ...
 timeSpent = ...
 practice_item_id = 123

 Can anyone explain where I might have mixed things up?

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: having trouble understanding associations

2010-03-26 Thread Johnny Ferguson
It's a little difficult to wrap my head around, but I think I see
what's going on.

belongsTo is a many to one relation, so many PracticeInstance belong
to 1 PracticeItem

That defies my intuition, because it's more natural for me to think of
a PracticeItem as belonging to a PracticeSession. The PracticeSession
has a PracticeItem.

I'll work through developing this app, and see if my understanding
doesn't grow a little. Thanks, Gian.

On Mar 26, 3:17 pm, Gianluca gc1...@googlemail.com wrote:
 Hello Johnny,

 class PracticeItem extends AppModel {

 }

 class PracticeInstance extends AppModel {
    var $belongsTo = 'PracticeItem';

 }

 class PracticeSession extends AppModel {
   var $hasMany = 'PracticeInstance';

 }

 tblPracticeInstances
 * id
 * practiceitem_id
 * practicesession_id
 * 

 tblPracticeSessions
 * id
 * 

 Let me know if you need more.

 Cheers,
 Gian.

 On 26 Mar, 18:57, Johnny Ferguson hyperfle...@gmail.com wrote:

  Looking 
  here:http://book.cakephp.org/view/78/Associations-Linking-Models-Together

  I'm certain my issue is due to a personal lack of understanding.

  I'm trying to homebrew a simple app to keep track of my guitar
  practice.

  I have the following models:
  PracticeItem: a specific exercise to be practiced any number of times
  PracticeInstance: an instance of having practiced one specific
  PracticeItem
  PracticeSession: a collection of PracticeInstance

  My immediate instinct is to say PracticeInstance hasOne
  PracticeItem.

  According to the Book: X hasOne Y = table Y having an X_id field.

  In my case PracticeInstance hasOne PracticeItem would mean:
  PracticeItems has a field practice_instance_id

  This makes no sense because if I were to create a PracticeItem called
  Major Scales 2, I would plan to practice it multiple times.

  If the field for this PracticeItem looks like
  id = 123
  title = Major Scales 2
  practice_instance_id = 23

  then I would have to duplicate the PracticeItem every time I practiced
  it.

  To me it would make more sense if PracticeInstance looked like:
  id  = primaryKey, autoincrement
  datetime = ...
  comment = ...
  timeSpent = ...
  practice_item_id = 123

  Can anyone explain where I might have mixed things up?

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Help understanding containable

2010-03-26 Thread kramers
I am trying to figure out how to use containable properly.

These are the model relationship:
Client has many Account
Account has many Bills
Bills have many BillResources
ResourceType hasMany BillResource
BillResources belong to bill
Bills belong to Account
Account belongs to Client


I am trying to only return BillResources that have a resource_type_id
= 2

So my query looks like
CODE
$this-Client-find('all',
  array(
   'contain'=array(
'Account' = array(
 'conditions' = array('Account.client_id = '=$this-Auth-
user('client_id')),
 'fields' = array('id'),
 'Bill' = array(
  'fields' = array('id'),
  'BillResource' = array(
   'conditions' =array(
'BillResource.resource_type_id =' = 1,

   )
  )
 )
),

),
'conditions'=array(
 'Client.id' = $this-Auth-user('client_id'),

)
  )
 );


However, the resulting array contains Bills with empty BillResources
because the resource_type_id does not equal 1. How do I correctly
query so that only Accounts with BillResource.resource_type_id = 1?
(As you can see below Account[0] and Account[1] should not be
returned)

If a bill does not have a bill with the proper resource type it would
not show up. If the account has no bills with the proper resource type
the account should not be returned.

Hope this was explained well...thanks in advance

CODE

Array
(
   [0] = Array
   (
   [Client] = Array
   (
   [id] = 3
   [name] = foo
   )

   [Account] = Array
   (
   [0] = Array
   (
   [id] = 6
   [client_id] = 3
   [Bill] = Array
   (
   [0] = Array
   (
   [id] = 32
   [account_id] = 6
   [BillResource] = Array
   (
   )

   )

   [1] = Array
   (
   [id] = 33
   [account_id] = 6
   [BillResource] = Array
   (
   )

   )
 )

   )

   [1] = Array
   (
   [id] = 7
   [client_id] = 3
   [Bill] = Array
   (
   [0] = Array
   (
   [id] = 36
   [account_id] = 7
   [BillResource] = Array
   (
   )

   )

   [1] = Array
   (
   [id] = 37
   [account_id] = 7
   [BillResource] = Array
   (
   )

   )

   [2] = Array
   (
   [id] = 38
   [account_id] = 7
   [BillResource] = Array
   (
   )

   )

   )

   )

   [2] = Array
   (
   [id] = 8
   [client_id] = 3
   [Bill] = Array
   (
   [0] = Array
   (
   [id] = 39
   [account_id] = 8
   [BillResource] = Array
   (
   [0] = Array
   (
   [id] = 60
 
[resource_type_id] = 1
   )

   )

 

Re: Problem understanding how this model object works

2009-12-30 Thread paulus websta
Cake is auto-loading your model, meaning that it cant find the model
you are expecting. Double check your spelling etc for the $uses var to
check your correctly assigning it.

On Dec 30, 6:37 am, edwingt edwin.al...@gmail.com wrote:
 I have a model object called ImpresorasProducto that belongs to a
 NxM relationship table impresoras_productos.

 When I'm in ImpresorasProductosController and debug the model object
 it prints this:

 ImpresorasProducto Object
 (
     [name] = ImpresorasProducto
     [belongsTo] = Array
         (
             [Producto] = Array
                 (
                     [className] = Producto
                     [foreignKey] = producto_id
 

 This is find because I can access al the realational models.

 The problem is when I use the ImpresorasProducto model in other
 controller.
 I include the model in the controller with the var $uses 
 I can't acces the objects related to ImpresorasProducto  and when I
 debug the model object it prints this:

 AppModel Object
 (
     [useDbConfig] = default
     [useTable] = impresoras_productos
     [displayField] = id
     [id] =
     [data] = Array
         (
         )

     [table] = impresoras_productos
 

 I cant uderstand why here I have an AppModel Object instead of a
 ImpresorasProducto Object

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


Problem understanding how this model object works

2009-12-29 Thread edwingt
I have a model object called ImpresorasProducto that belongs to a
NxM relationship table impresoras_productos.

When I'm in ImpresorasProductosController and debug the model object
it prints this:

ImpresorasProducto Object
(
[name] = ImpresorasProducto
[belongsTo] = Array
(
[Producto] = Array
(
[className] = Producto
[foreignKey] = producto_id


This is find because I can access al the realational models.

The problem is when I use the ImpresorasProducto model in other
controller.
I include the model in the controller with the var $uses 
I can't acces the objects related to ImpresorasProducto  and when I
debug the model object it prints this:

AppModel Object
(
[useDbConfig] = default
[useTable] = impresoras_productos
[displayField] = id
[id] =
[data] = Array
(
)

[table] = impresoras_productos


I cant uderstand why here I have an AppModel Object instead of a
ImpresorasProducto Object

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


understanding blackHoleCallback

2009-07-28 Thread Luke

Hi,

I am using the Security component, but would like to make sure that if
the security check fails, the User will get an Error message displayed
inside the Layout.

So, when I use just:

$this-Security-blackHole($this, 'You are not authorized to process
this request!');

I only get a blank white page with nothing else displayed. So I added:

$this-Security-blackHoleCallback = 'accessError';


With this, I now get the You are not authorized to process this
request! displayed, but it sits outside of my Layout, its actually
even outside the !DOCTYPE 

What am I doing wrong? If I understand right, than I would need a
function accessError() , but what do i need to add into this to make
sure it is all in one Layout? I look forward to any help, I have read
backwards and forwards through the www but could not find an answer.
Thanks a lot for your help.

Luke
--~--~-~--~~~---~--~~
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: Not fully understanding associations. Id showing instead of name.

2009-05-18 Thread number9

Yes it's a varchar and I utilised bake, I've got it working now by
setting recursive to 2 and amending the views to use the other models
field, I just wondered if there was a more efficient way of doing it
as I should imagine it is a common thing to do, but if not, not to
worry - thanks for the replies!



On May 16, 12:59 pm, j0n4s.h4rtm...@googlemail.com
j0n4s.h4rtm...@googlemail.com wrote:
 Is the name field a varchar255 not null or tinytext?
 Try using cake bake to create your starting environment and work from
 there

 On May 15, 5:38 pm, number9 xpozit...@gmail.com wrote:



  Actually I tried displayfield earlier when I was searching, but it
  didn't work, presumably because: The model will use name or title, by
  default. and I am trying to output name (so it should be doing that
  anyway).

  On May 15, 4:33 pm, number9 xpozit...@gmail.com wrote:

   OK, so I tried setting recursive to two again (didn't work earlier)
   and it worked!

   Is there a better method to do this for future reference as it seems
   to place a bit of a load of the database...

   On May 15, 4:12 pm, number9 xpozit...@gmail.com wrote:

Hi all,

Apologies for this newbish question, I've searched for hours trying to
resolve this with no joy so would appreciate it if you could point me
in the right direction.

I'm trying to setup a simple website (my first cakephp project, having
become OKish at PHP/MYSQL).

Basically there are three models so far, posts, categories and sites
(all of the databases follow cake naming conventions, with id as PK,
name and _id for FKs.

Posts belong to categories.

Posts also belong to sites.

Categories, and sites have one post.

I have used cake bake to generate the controllers and views. /posts/
works great, and it shows everything by name, the add works great in
terms of the relationships.

The problem I am having is, when I go to /categories/, it brings up
posts under that category and the category and site are showing up
as numbers rather than name (in the view they are category_id, and
site_id). I can get the category name to show up OK (because I think
that table is mapped).

What I don't understand is why the name is not showing in place of the
_id like everwhere else. How can I output database fields in another
model. It is probably something really simple, but I'm getting used to
the cake way of thinking.

Is it that the relationship is wrong? The query at the bottom shows
the names are being selected.

Thanks in advance
--~--~-~--~~~---~--~~
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: Not fully understanding associations. Id showing instead of name.

2009-05-16 Thread j0n4s.h4rtm...@googlemail.com

Is the name field a varchar255 not null or tinytext?
Try using cake bake to create your starting environment and work from
there

On May 15, 5:38 pm, number9 xpozit...@gmail.com wrote:
 Actually I tried displayfield earlier when I was searching, but it
 didn't work, presumably because: The model will use name or title, by
 default. and I am trying to output name (so it should be doing that
 anyway).

 On May 15, 4:33 pm, number9 xpozit...@gmail.com wrote:

  OK, so I tried setting recursive to two again (didn't work earlier)
  and it worked!

  Is there a better method to do this for future reference as it seems
  to place a bit of a load of the database...

  On May 15, 4:12 pm, number9 xpozit...@gmail.com wrote:

   Hi all,

   Apologies for this newbish question, I've searched for hours trying to
   resolve this with no joy so would appreciate it if you could point me
   in the right direction.

   I'm trying to setup a simple website (my first cakephp project, having
   become OKish at PHP/MYSQL).

   Basically there are three models so far, posts, categories and sites
   (all of the databases follow cake naming conventions, with id as PK,
   name and _id for FKs.

   Posts belong to categories.

   Posts also belong to sites.

   Categories, and sites have one post.

   I have used cake bake to generate the controllers and views. /posts/
   works great, and it shows everything by name, the add works great in
   terms of the relationships.

   The problem I am having is, when I go to /categories/, it brings up
   posts under that category and the category and site are showing up
   as numbers rather than name (in the view they are category_id, and
   site_id). I can get the category name to show up OK (because I think
   that table is mapped).

   What I don't understand is why the name is not showing in place of the
   _id like everwhere else. How can I output database fields in another
   model. It is probably something really simple, but I'm getting used to
   the cake way of thinking.

   Is it that the relationship is wrong? The query at the bottom shows
   the names are being selected.

   Thanks in advance
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Not fully understanding associations. Id showing instead of name.

2009-05-15 Thread number9

Hi all,

Apologies for this newbish question, I've searched for hours trying to
resolve this with no joy so would appreciate it if you could point me
in the right direction.

I'm trying to setup a simple website (my first cakephp project, having
become OKish at PHP/MYSQL).

Basically there are three models so far, posts, categories and sites
(all of the databases follow cake naming conventions, with id as PK,
name and _id for FKs.

Posts belong to categories.

Posts also belong to sites.

Categories, and sites have one post.

I have used cake bake to generate the controllers and views. /posts/
works great, and it shows everything by name, the add works great in
terms of the relationships.

The problem I am having is, when I go to /categories/, it brings up
posts under that category and the category and site are showing up
as numbers rather than name (in the view they are category_id, and
site_id). I can get the category name to show up OK (because I think
that table is mapped).

What I don't understand is why the name is not showing in place of the
_id like everwhere else. How can I output database fields in another
model. It is probably something really simple, but I'm getting used to
the cake way of thinking.

Is it that the relationship is wrong? The query at the bottom shows
the names are being selected.

Thanks in advance

--~--~-~--~~~---~--~~
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: Not fully understanding associations. Id showing instead of name.

2009-05-15 Thread fain182

set $displayField in the model..
http://book.cakephp.org/view/438/displayField

-- 
pietro

--~--~-~--~~~---~--~~
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: Not fully understanding associations. Id showing instead of name.

2009-05-15 Thread number9

OK, so I tried setting recursive to two again (didn't work earlier)
and it worked!

Is there a better method to do this for future reference as it seems
to place a bit of a load of the database...

On May 15, 4:12 pm, number9 xpozit...@gmail.com wrote:
 Hi all,

 Apologies for this newbish question, I've searched for hours trying to
 resolve this with no joy so would appreciate it if you could point me
 in the right direction.

 I'm trying to setup a simple website (my first cakephp project, having
 become OKish at PHP/MYSQL).

 Basically there are three models so far, posts, categories and sites
 (all of the databases follow cake naming conventions, with id as PK,
 name and _id for FKs.

 Posts belong to categories.

 Posts also belong to sites.

 Categories, and sites have one post.

 I have used cake bake to generate the controllers and views. /posts/
 works great, and it shows everything by name, the add works great in
 terms of the relationships.

 The problem I am having is, when I go to /categories/, it brings up
 posts under that category and the category and site are showing up
 as numbers rather than name (in the view they are category_id, and
 site_id). I can get the category name to show up OK (because I think
 that table is mapped).

 What I don't understand is why the name is not showing in place of the
 _id like everwhere else. How can I output database fields in another
 model. It is probably something really simple, but I'm getting used to
 the cake way of thinking.

 Is it that the relationship is wrong? The query at the bottom shows
 the names are being selected.

 Thanks in advance
--~--~-~--~~~---~--~~
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: Not fully understanding associations. Id showing instead of name.

2009-05-15 Thread number9

Actually I tried displayfield earlier when I was searching, but it
didn't work, presumably because: The model will use name or title, by
default. and I am trying to output name (so it should be doing that
anyway).

On May 15, 4:33 pm, number9 xpozit...@gmail.com wrote:
 OK, so I tried setting recursive to two again (didn't work earlier)
 and it worked!

 Is there a better method to do this for future reference as it seems
 to place a bit of a load of the database...

 On May 15, 4:12 pm, number9 xpozit...@gmail.com wrote:



  Hi all,

  Apologies for this newbish question, I've searched for hours trying to
  resolve this with no joy so would appreciate it if you could point me
  in the right direction.

  I'm trying to setup a simple website (my first cakephp project, having
  become OKish at PHP/MYSQL).

  Basically there are three models so far, posts, categories and sites
  (all of the databases follow cake naming conventions, with id as PK,
  name and _id for FKs.

  Posts belong to categories.

  Posts also belong to sites.

  Categories, and sites have one post.

  I have used cake bake to generate the controllers and views. /posts/
  works great, and it shows everything by name, the add works great in
  terms of the relationships.

  The problem I am having is, when I go to /categories/, it brings up
  posts under that category and the category and site are showing up
  as numbers rather than name (in the view they are category_id, and
  site_id). I can get the category name to show up OK (because I think
  that table is mapped).

  What I don't understand is why the name is not showing in place of the
  _id like everwhere else. How can I output database fields in another
  model. It is probably something really simple, but I'm getting used to
  the cake way of thinking.

  Is it that the relationship is wrong? The query at the bottom shows
  the names are being selected.

  Thanks in advance
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



understanding shoppping carts w/ MVC, new to cake

2009-03-19 Thread squall2...@gmail.com

 I know this is a long post, i'm sorry. I'm just trying to get advice
on how to structure this code the right way. Alright, I've been
programming php off and on for a few years now, but i'm new to cakephp
1.2. I'm working on a project that involves a shopping cart for
ordering food. After talking to a friend of mine he explained it would
be best to design the shopping cart ordering process using a concept
called 'LineItems'. This concept pretty much says that you split the
order into 'lines' and each lineitem contains a product the person
ordered, and all the information about that product, (the quanitity,
the price, the name of the product, etc, etc). Then an 'order' is the
collection of Lineitems for that user. LineItems and orders are
associated with an 'order_id'. That way you look up an order from the
'orders' table using the 'order_id' and grab all of the assicated
LineItems with that order_id as the prmary key. okay so good so far.
Now the problem is the how do i translate this to Model View
Controller terms? The way i have things set up now is:

Controllers:
The user will be able to place multiple orders at once (orders for
future dates, and orders for that day). So right now i'm only working
with placing a single order with a controller called
'singleOrderController

Models:
Then I have an 'order' model which writes to an 'orders' database
table
Then i have a 'LneItem' model that writes to a 'LineItems database
table

Assocations
order-HasMany 'LineItem'
LineItem-BelongsTo 'order'

Database tables:
menuItems - contains a list of food items offered by the company
lineItems- contains a list of menuItems that user has ordered, the
quanity etc. AND the 'order_id'
orders-contains the order_id and the 'order_number'

so the code i have to do the processing so far is

CODE

foreach ($this-data['menuitems'] as $id = $quantity){
   if($quantity0){ //and is numeric
   $this-LineItem-create(array(order_id = $this-
order-data['order_id'], quantity=$quantity, menuitem_id=$id));
   $this-order-save($this-LineItem-data);
   }


So the way this works is it grabs 1 line of input from the post data,
and assigns it to a lineitem, then it *HAS* to save the lineitem to
the database or else it erases it with new content. To me this just
seems stupid. The way that i would like to code this is to have an
order be an object, containing lineitems which are objects as well.
Then once you have ALL The information, you parse the data and insert
it into a database. But that doesn't seem to follow the model view
controller design pattern. Am i just not doing this right, or are
there a lot of concept behind the model view controller that i'm not
understanding? if someone could tell me how they would code this for
the best flexibility in mind, PLEASE i'm looking for ANY answers as to
how i'm messing this up, and how to design this better.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Understanding ACL

2009-03-09 Thread Dave Maharaj :: WidePixels.com
I have been reading more into ACL in the Cookbook and have been making
changes to the application I have been working on. I see in the cookbook:
 
Fellowship of the Ring
(Deny: all) 

*   Warriors
(Allow: Weapons, Ale, Elven Rations, Salted Pork) 


*   Aragorn
(Allow: Diplomacy)
*   Legolas
*   Gimli

*   Wizards
(Allow: Salted Pork, Diplomacy, Ale) 


*   Gandalf

*   Hobbits
(Allow: Ale) 


*   Frodo
(Allow: Ring)
*   Bilbo
*   Merry
(Deny: Ale)
*   Pippin
(Allow: Diplomacy)

*   Visitors
(Allow: Salted Pork) 


*   Gollum

I was wondering how to go about changing what a user is allowed. Easiest
example in terms of writing it out would be something like you can go to
the theatre to watch a movie but unless you pay your only going to wait in
the lobby
 
So they have access to the movieTheater_controller but they dont have
permission to the view_movie function() unless they paid admission. So the
permission is based temporarily if they paid and once the movie is over
your access is denied. Hope that makes some kind of sense. 
 
 
Dave 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Understanding Acl with Auth

2009-02-18 Thread rinda

Hi,

I spent days understanding this acl stuff. I made progress but
still

I have groups:
id:1, name:administrators
id:2, name:managers
id:3, name:users

I have users:
id:1, name:admin, group_id:1
id:2, name:mana, group_id:2
id:3, name:user, group_id:3

I have aros:
id:1, parent_id:null, model:Group, foreign_key:1,
alias:administrators, lft:1, rght:4
id:2, parent_id:null, model:Group, foreign_key:2, alias:managers, lft:
5, rght:8
id:3, parent_id:null, model:Group, foreign_key:3, alias:users, lft:9,
rght:12
id:4, parent_id:1, model:User, foreign_key:1, alias:admin, lft:2, rght:
3
id:5, parent_id:2, model:User, foreign_key:2, alias:mana, lft:6, rght:
7
id:6, parent_id:3, model:User, foreign_key:3, alias:user, lft:10, rght:
11

I have acos:
id:1, parent_id:null, alias:controllers, lft:1, rght:6
id:2, parent_id:1, alias:bla, lft:2, rght:3
id:3, parent_id:1, alias:she, lft:4, rght:5

I have aros_acos:
id:1, aro_id:2, aco_id:2, _read,_create,_update,_delete: 1
id:2, aro_id:2, aco_id:3, _read,_create,_update,_delete: 1
id:3, aro_id:3, aco_id:3, _read,_create,_update,_delete: 1

These are bla and she controller:
class [Bla/She]Controller extends AppController
{
  var $uses = array();
  function testing()
  {
echo Acl makes me crazy.;
$this-autoRender = false;
  }
}

This is User model:
class User extends AppModel
{
  var $name = 'User';
  var $belongsTo = array('Group');
  var $actsAs = array('Acl' = array('requester'));

  function parentNode()
  {
if (!$this-id  empty($this-data))
{
  return null;
}
$data = $this-data;
if (empty($this-data))
{
  $data = $this-read();
}
if (!$data['User']['group_id'])
{
  return null;
}
else
{
  return array('Group' = array('id' = $data['User']
['group_id']));
}
  }
}

This is Group model:
class Group extends AppModel
{
  var $name = 'Group';
  var $actsAs = array('Acl' = array('requester'));

  function parentNode()
  {
return null;
  }
}

This is my app_controller file:
class AppController extends Controller
{
  var $components = array('Acl', 'Auth');

  function beforeFilter()
  {
$this-Auth-authorize = 'actions';
$this-Auth-loginAction = array('controller' = 'users', 'action'
= 'login');
$this-Auth-logoutRedirect = array('controller' = 'users',
'action' = 'login');
$this-Auth-loginRedirect = array('controller' = 'users',
'action' = 'login');
$this-Auth-actionPath = 'controllers/';
  }
}

If I log in with user 'mana' (group = 'managers') then go to this
page: /bla/testing, I get this error:
DbAcl::check() - Failed ARO/ACO node lookup in permissions check.
Node references:

Aco: controllers/Bla/testing

But if I put another aco node with alias 'testing' and parent node
points to 'bla', I can access it.
id:4, parent_id:2, alias:testing, lft:3, rght:4

I am very confused. How should you name the aco (controller stuff)?
How do I use _read, _create, etc field effectively? Why do I get
failed node lookup rather than denied access?

Thank you.

--~--~-~--~~~---~--~~
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: Understanding if a model-controller couple is needed

2008-12-03 Thread Fabio M

Thank you very much. I had reached the same conclusion while I was
waiting for replies and now you make me more self-confident.
I have no much experience in actual developing, so an extremely
minimal approach to the E-R diagram influenced me.

Again, thank you.


 Are your relationships really HABTM, or are they parent-child? I would
 think that you'd have:

    1. Movies has many Reviews
    2. Reviewers has many Reviews
    3. Reviews belong to Movies and Reviewers

 On Nov 29, 11:43 am, Fabio M [EMAIL PROTECTED] wrote:


--~--~-~--~~~---~--~~
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: Understanding if a model-controller couple is needed

2008-11-30 Thread Rob

The answer as always is it depends (but in this case I think the
answer is yes you need a model for the review).

First I would suggest that your movies_reviewers might be named
reviews, since it sounds like that is what you're putting in it.

If you will be accessing data from the review, then you need a model
for it. Personally I tend to model the relationships of all of the
tables using cake bake, then go back and make sure all the
relationships are reflected in the models that I will be driving my UI
with.

Are your relationships really HABTM, or are they parent-child? I would
think that you'd have:

   1. Movies has many Reviews
   2. Reviewers has many Reviews
   3. Reviews belong to Movies and Reviewers

On Nov 29, 11:43 am, Fabio M [EMAIL PROTECTED] wrote:
 Hi all. This is my first message here.
 I want to make it clear first that I read the (almost) whole
 documentation and now I'm going to develop a first application. I
 still have a doubt about dealing with HABTM relationship.

 I give you the precise picture.

 I have two entities: movie (motion picture) and reviewer. These are in
 a HABTM relationship, which represents the review. I'll create the
 conventional db tables: movies, reviewers and movies_reviewers. Note
 that movies_reviewers isnt just a join-table, it includes other
 informations beyond the foreign key (the vote of the review, the text
 of the review).

 Now I ask: do I need a model for the review? Is the review an object
 in my application?

 If so, which table should this model class be linked to? Directly to
 join-table?

 Should I make a whole another design? Dont know...  with three
 entities (movie, review, reviewers) and two merely associative
 relationships (with a movie_id and a reviewer_id in the reviews
 table)?

 Thank you. And forgive me for bad explanation and for not having found
 this topic in other threads. I'm italian and I'm a bit in difficulty
 at retrieving technical infos in a foreign language.

 Thank you in advance.  : )

                       Fabio M
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Understanding if a model-controller couple is needed

2008-11-29 Thread Fabio M

Hi all. This is my first message here.
I want to make it clear first that I read the (almost) whole
documentation and now I'm going to develop a first application. I
still have a doubt about dealing with HABTM relationship.

I give you the precise picture.

I have two entities: movie (motion picture) and reviewer. These are in
a HABTM relationship, which represents the review. I'll create the
conventional db tables: movies, reviewers and movies_reviewers. Note
that movies_reviewers isnt just a join-table, it includes other
informations beyond the foreign key (the vote of the review, the text
of the review).

Now I ask: do I need a model for the review? Is the review an object
in my application?

If so, which table should this model class be linked to? Directly to
join-table?

Should I make a whole another design? Dont know...  with three
entities (movie, review, reviewers) and two merely associative
relationships (with a movie_id and a reviewer_id in the reviews
table)?

Thank you. And forgive me for bad explanation and for not having found
this topic in other threads. I'm italian and I'm a bit in difficulty
at retrieving technical infos in a foreign language.

Thank you in advance.  : )

  Fabio M

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Help understanding magic on view field id and populating another field through that

2008-11-01 Thread carlos ferrandis

Hello everybody

I keep my struggle to learn the cake way (not carlitos' way). Please
suppose I have the following

in my add view ORDERS

echo $form-input('item_id');

which returns the field name in a select due to the association, and
is working fine, where item_id is my foreign key.

bellow on the same view...

echo $form-input('value');

I would like cake to ONCHANGE event ($form-input('item_id');)
suggest a value to  $form-input('value'); based on values read from
ITEMS table.

I have done this without ajax in non-cake projects, reading all ITEMS
with names and values, maintaining the data in a array, assembling the
select input based on valued and ONCHANGE displaying the value using
div for the value field.

I wish to know how would you guys resolve a similar problem but
besides I would like to learn what happens behind the scenery when you
do echo $form-input('item_id'); and cake brings bake the field name
in the select.

any help or direction would be more than appreciated.

Carlos
--~--~-~--~~~---~--~~
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: not understanding simple HABTM save/delete

2008-10-26 Thread RyOnLife


After hours and hours of frustration, I've figured it out. It wasn't fun, but
maybe not having my questions answered makes me a better programmer. For
future reference, it's actually pretty simple. I started with a new app with
my existing models and by baking new controllers/views I was able to figure
it out:

Since I'm applying a 'Label' to an 'Item', I just save() to my 'Item' model:

$this-Item-save($data);

And pr($data) looks like this:

Array
(
[Item] = Array
(
[id] = 1
)
[Label] = Array
(
[Label] = Array
(
[0] = 4
[1] = 5
[2] = 7
[3] = 8
)
)
)

I also found that delete() isn't necessary. Before the new
associations/records are inserted in 'items_labels' for a given 'item_id'
(in the case, it's 1), all of the existing records for that 'item_id' are
deleted.
-- 
View this message in context: 
http://n2.nabble.com/not-understanding-simple-HABTM-save-delete-tp1377073p1380365.html
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



not understanding simple HABTM save/delete

2008-10-25 Thread RyOnLife


After spinning my wheels for a few hours on this one, any help would be very
appreciated...

I have an 'Item' model:

class Item extends AppModel {  
  var $name = 'Item';  
  var $hasAndBelongsToMany = 'Label';
}

A 'Label' model:

class Label extends AppModel {  
  var $name = 'Label';  
  var $hasAndBelongsToMany = 'Item';
}

And an 'items_labels' join table:

CREATE TABLE `items_labels` (
  `item_id` int(11) NOT NULL,
  `label_id` int(11) NOT NULL,
  `created` datetime default NULL
);

I cannot figure out how to save a simple record (association) to the join
table. I just don't understand what I need to put in my
'labels_controller.php' to get this result, for example:

INSERT INTO `database_name`.`items_labels` (`item_id`, `label_id`,
`created`) VALUES ('1', '1', NOW());

After many failed attempts, I'm back to an empty action:

function update($item_id, $label_id) {

}

In addition to save(), help with delete() would also be appreciated.

And not sure if it has any bearing on the solution, but for this action, I
am not concerned with any of the records in the 'items' or 'labels' tables.

Many thanks!

-Ryan
-- 
View this message in context: 
http://n2.nabble.com/not-understanding-simple-HABTM-save-delete-tp1377073p1377073.html
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



trouble understanding saveAll and beforeSave()

2008-09-01 Thread [EMAIL PROTECTED]

Hi there,

I'm having trouble to understand the way saveAll works.
I have to models. One for storing addresses and the other one to
protocol changes on the addresses.

class Adresse extends AppModel {
var $name = 'Adresse';

var $hasMany = 'Adressenchangelog';
-- snip --

class Adressenchangelog extends AppModel {
var $name = 'Adressenchangelog';

var $belongsTo = 'Adresse';
}


The changelog should be created within beforeSave(). After testing
different kinds of how to write this to be saved, I'm stuck now.

This is the manual Test - and dowsn't work (undefined index-warning in
model.php):
$this-data['Adressenchangelog'] = array('adresse_id' = $this-
data['Adresse']['id'], 'user_realname' = 'jaja');
$this-Adresse-saveAll($this-data, array('validate'='first'));

If I try this, it still doesn't work:
$this-data['Adresse']['Adressenchangelog'] = array('adresse_id' =
$this-data['Adresse']['id'], 'user_realname' = 'jaja');

If I split the save-Commands like that, it works:
$this-Adresse-save( $this-data );
$this-Adresse-Adressenchangelog-save( $this-Adresse-
Adressenchangelog-data );


So how do I need to set this up?

thanks in advance
Klaus

--~--~-~--~~~---~--~~
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: Vendors: Trouble understanding+correct use

2008-08-30 Thread spyros k.

Hi again, I am still searching for an answer regarding vendors in
cakephp and haven't found anything yet.
Could someone please explain to me how to use them correctly, or if
there is a tutorial/howto that I can read?

Just in case someone has the patience to read it i am posting below
the code of s3.php :

?php
/**
* $Id: S3.php 33 2008-07-30 17:30:20Z don.schonknecht $
*
* Copyright (c) 2007, Donovan Schonknecht.  All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
are met:
*
* - Redistributions of source code must retain the above copyright
notice,
*   this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
*   notice, this list of conditions and the following disclaimer in
the
*   documentation and/or other materials provided with the
distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
AS IS
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/**
* Amazon S3 PHP class
*
* @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class
* @version 0.3.3
*/
class S3 {
// ACL flags
const ACL_PRIVATE = 'private';
const ACL_PUBLIC_READ = 'public-read';
const ACL_PUBLIC_READ_WRITE = 'public-read-write';

public static $useSSL = true;

private static $__accessKey; // AWS Access key
private static $__secretKey; // AWS Secret key


/**
* Constructor, used if you're not calling the class statically
*
* @param string $accessKey Access key
* @param string $secretKey Secret key
* @param boolean $useSSL Whether or not to use SSL
* @return void
*/
public function __construct($accessKey = null, $secretKey = null,
$useSSL = true) {
if ($accessKey !== null  $secretKey !== null)
self::setAuth($accessKey, $secretKey);
self::$useSSL = $useSSL;
}


/**
* Set access information
*
* @param string $accessKey Access key
* @param string $secretKey Secret key
* @return void
*/
public static function setAuth($accessKey, $secretKey) {
self::$__accessKey = $accessKey;
self::$__secretKey = $secretKey;
}


/**
* Get a list of buckets
*
* @param boolean $detailed Returns detailed bucket list when true
* @return array | false
*/
public static function listBuckets($detailed = false) {
$rest = new S3Request('GET', '', '');
$rest = $rest-getResponse();
if ($rest-error === false  $rest-code !== 200)
$rest-error = array('code' = $rest-code, 'message' =
'Unexpected HTTP status');
if ($rest-error !== false) {
trigger_error(sprintf(S3::listBuckets(): [%s] %s, 
$rest-
error['code'], $rest-error['message']), E_USER_WARNING);
return false;
}
$results = array(); //var_dump($rest-body);
if (!isset($rest-body-Buckets)) return $results;

if ($detailed) {
if (isset($rest-body-Owner, $rest-body-Owner-ID, 
$rest-body-
Owner-DisplayName))
$results['owner'] = array(
'id' = (string)$rest-body-Owner-ID, 'name' 
= (string)$rest-
body-Owner-ID
);
$results['buckets'] = array();
foreach ($rest-body-Buckets-Bucket as $b)
$results['buckets'][] = array(
'name' = (string)$b-Name, 'time' = 
strtotime((string)$b-
CreationDate)
);
} else
foreach ($rest-body-Buckets-Bucket as $b) $results[] 
= (string)
$b-Name;

return $results;
}


/*
* Get contents for a bucket
*
* If maxKeys is null this method will loop through truncated result
sets
*
* @param string $bucket Bucket name
* @param string $prefix Prefix
* 

Re: Vendors: Trouble understanding+correct use

2008-08-30 Thread spyros k.

Ok, it's solved.
--~--~-~--~~~---~--~~
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: Vendors: Trouble understanding+correct use

2008-08-30 Thread Dardo Sordi Bogado

For the record: http://book.cakephp.org/view/538/loading-vendor-files

On Sat, Aug 30, 2008 at 6:50 PM, spyros k. [EMAIL PROTECTED] wrote:

 Ok, it's solved.
 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Vendors: Trouble understanding+correct use

2008-08-29 Thread spyros k.

Hi, I am trying to use s3.php from underdesigned (http://
undesigned.org.za/2007/10/22/amazon-s3-php-class) and I dont
understand how to make it work.

What i've done so far is to put it in app/vendors folder and wrote
this code on a view that I want to have s3 functionality:

?php
App::import('Vendor','s3');
$s3 = new s3(,,0);
echo S3::listBuckets(): .print_r($s3-listBuckets(), 1).\n;
?

where  is my awsAccessKey and awsSecrtekey.

Why isn't this working? What am I doing wrong here?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



I need help with understanding the webroot directory

2007-11-02 Thread brehg

I'm new to cakePHP and have a basic web application up and running.
Can someone please explain the webroot directory and the webroot/
index.php file. I would like to have my own index page load using the
standard MVC like every other view I have created. The index.php page
is somehow reading in my default view/wrapper correctly but I'm not
sure how it is being built.


--~--~-~--~~~---~--~~
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: I need help with understanding the webroot directory

2007-11-02 Thread Dardo Sordi Bogado
Also take a look at app/config/routes.php

2007/11/2, jinhr [EMAIL PROTECTED]:

 webroot is viewed from client-side (that is web browser).
 So if a file is webroot/img/logo.jpg. It is publicly accessible as
 http://www.mydomain.com/img/logo.jpg;

 On 11月2日, 上午11时08分, brehg [EMAIL PROTECTED] wrote:
  I'm new to cakePHP and have a basic web application up and running.
  Can someone please explain the webroot directory and the webroot/
  index.php file. I would like to have my own index page load using the
  standard MVC like every other view I have created. The index.php page
  is somehow reading in my default view/wrapper correctly but I'm not
  sure how it is being built.


 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Addendum to Joshua Benner's Understanding CakePHP Associations

2007-09-07 Thread Gould, Adrian

Hi all, I've done a little addendum to JB's article on CakePHP Associations 
(CPA) to include the Entity-Relationship Diagram (ERD) equivalents.

You can find it here: 
http://it.swantafe.wa.edu.au/index.php?option=com_contenttask=viewid=105Itemid=49

I found it hard to get the brain around the CPA to ERD and visa versa... so I 
hope that the diagrams are now correct...


Feel free to shoot me down in flames ;-)

Adrian

--~--~-~--~~~---~--~~
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: need some help in understanding error messages

2007-08-24 Thread rtanz

i think there might have been some syntax errors so i fixed it as
follows, however it is still not working. any help?

function beforeValidate() {
// for add -there is no id
if (!isset($this-data['User']['id'])  !empty($this-
data['User']['name'])
 $this-hasAny(User.name=$this-data['User']['name']))
{
   $this-invalidate('name_unique');
}

 // for edit - there is id
if (isset($this-data['User']['id'])  !empty($this-
data['User']['name'])
  $this-findCount(User.name = $this-data['User']
['name'])) {
$this-invalidate('name_unique');
}
return true;
}


--~--~-~--~~~---~--~~
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: need some help in understanding error messages

2007-08-23 Thread housebolt

The easiest way to do this is by using $this-Session-
setFlash('Username already exists'); in your controller. The error
message will show up at the top of the page or wherever you put if
($session-check('Message.flash')) $session-flash(); in your layout.

On Aug 23, 7:33 am, rtanz [EMAIL PROTECTED] wrote:
 hi right now i have baked a model with an add and edit view as
 automatically generated by cake. So now if I make any errors when
 saving (as determined by the $validate conditions below) I will get
 the values of the tagErrorMsg as set in the view. Now I also made a
 beforeSave function that checks whether a user with that username
 exists already, and in that case I would like to output a different
 message saying that 'Username already exists' instead of 'Please enter
 the Username'. How can i do this? thanks

 class User extends AppModel
 {
 var $name = 'User';
 var $hasMany = array('Membership'=array('dependent'=true));

 var $validate = array(
   'username' = '/[a-z0-9\_\-]{3,}$/i',
   'password' = VALID_NOT_EMPTY,
   'email' = VALID_EMAIL,
);

 function beforeSave() {
 $user = $this-data['User']['username'];
 $conditions = array(User.username=$user);
 if ($this-find($conditions)) {
 return false;
 }
 else return true;
 }

 }

 ?php echo $html-tagErrorMsg('User/username', 'Please enter the
 Username.');?


--~--~-~--~~~---~--~~
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: need some help in understanding error messages

2007-08-23 Thread rtanz

but what if i have more than one error? am i correct in that you can
have only one set flash message?


--~--~-~--~~~---~--~~
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: need some help in understanding error messages

2007-08-23 Thread majna

Model:
function beforeValidate()
{
# for add -there is no id
if (!isset($this-data[$this-name]['id'])  !empty($this-
data[$this-name]['name']) $this-hasAny(User.name='{$this-
data['User']['name']}' ) )
{
$this-invalidate('name_unique');
}
# for edit - there is id
if (isset($this-data[$this-name]['id'])  !empty($this-
data[$this-name]['name'])  $this-findCount(User.name = '{$this-
data[$this-name]['name']}' )
{
$this-invalidate('name_unique');
}

return true;
}

View:
?php echo $html-tagErrorMsg('User/username', 'Please enter the
Username.');?
?php echo $html-tagErrorMsg('User/name_unique', 'Username
exists...');?



On Aug 23, 10:49 pm, rtanz [EMAIL PROTECTED] wrote:
 but what if i have more than one error? am i correct in that you can
 have only one set flash message?


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Structuring and modelling applications and just understanding the workings of cakePHP

2007-07-18 Thread DrLaban

Hello there!

So I've started to get the hang of how the models, controllers and
views work together. It was a bit of an uphill to start with but I've
managed to create quite a few good, sound working sections in cakePHP
which makes me think that I at least have some knowledge about how
things should work.

Now, I've been thinking about a specific part of an application I'm
building and it has to do with newsletters and e-mail registrations.

The section of the application's different functions are simple
enough;
* Index (Here you have the option to click subscribe and unsubscribe
links)
* Subscribe (Provide a valid email address, this in turn sends an
email sent to you with a verification code)
* Verify (With the help of your address and verification code, you
verify that you've recieved the subscription email)
* Unsubscribe (Provide an email-address to unsubscribe)

I'm almost done with the entire section but I'm becoming more and more
unsure if I'm attacking this from the right angles. It seems, as I've
gotten further and further into trying to figure out how to solve
different types of things, I'm more and more letting go of cakePHP's
structure, almost coding everything by hand as I would without using
cake.

For example; The registration page. It works perfect, I get an email
sent to me and whatnot but I've lost some of cakePHP's powers in the
process.
On the registration page I've got the following in my controller:
if(!empty($this-data)) {
$this-data['Lunch']['code'] = $this-Generic-
generatePassword(4);
if($this-Lunch-save($this-data)) {
$this-Generic-sendEmail($this-data['Lunch']['email'], $this-
data['Lunch']['code']);
$this-flash('Data saved!', '/newsletter');
}
}

As you can see I'm using a component called Generic (I had a bit of
a dry-out when choosing name, I'm aware) which holds both code
generating functions and email handling. The view only consists of one
field so far; Enter your email address. It works fine insofar that
if I don't provide an email address, I don't get an email and the
address isn't stored anywhere. If I do provide an email address, but
it's in the wrong format, I get notified of this by cake's built-in
error handler. If I provide a correct email address, everything is
working and I get a flash-message that everything has worked out.

The model is very simple:
class Newsletter extends AppModel {
var $name = 'Newsletter';

var $validate = array(
'email' = VALID_EMAIL
);
}

Not very much to comment on here.

The view:
Subscribe to our newsletter
form name=lunchForm method=post action=register
Email address: ?php echo $html-input('Newsletter/email',
array('size' = 20)); ??php echo $html-tagErrorMsg('Newsletter/
email', 'You have to provide a valid email address!'); ?
?php echo $html-submit('Subscribe!'); ?
/form

As the model states, it gives me an error when the address is in the
wrong format but do I have to state some other validation method to
make it work with an empty field?

What I've lost here in the process are the following:
* My database table of this consists of a unique field called email
apart from the regular id primary key field. When I enter an email
address that already exists in the database I get an ugly SQL-parse
error. None of the nicely styled and handled error messages that cake
provides.
* If I don't provide an email address, I get no error whatsoever. The
page reloads as if nothing's happened and I get to provide the address
again. I've completely and entirely lost the error handling.

Now, what I'd like to know is this; Am I going about this the right
way or am I not using cake's potential at all? Are there mutiple ways
of solving this?

Thank you for your time! It's much appreciated!

Regards
 DrLaban


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Understanding validator regex

2007-05-31 Thread Floyd

Hi,

I'm defining new regex validators in cake/validator.php file. I have
worked with regex in other projects but indeed I don't understand some
issues of the regex that was defined in cake by default.

Example:

define('VALID_EMAIL', '/\\A(?:^([a-z0-9][a-z0-9_\\-\\.\\+]*)@([a-z0-9]
[a-z0-9\\.\\-]{0,63}\\.(com|org|net|biz|info|name|net|pro|aero|coop|
museum|[a-z]{2,4}))$)\\z/i');

I don't understand:
- Why is used a double escape \\ bar instead of a single bar \
- What is the meaning of A(?: at start of regex
- Why there is a / at start
-What is the meaning of \\z/i at final of regex

I searched for regex manuals in google but i not found response for my
doubts. Neither in this googlegroup.

Excuse me for my bad english and if my doubts are basic.


--~--~-~--~~~---~--~~
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: Understanding validator regex

2007-05-31 Thread Davide

Floyd wrote:
 I don't understand:
 - Why is used a double escape \\ bar instead of a single bar \

I think bacause with a single slash in a string you mean that you want
to escape the following character. So \\ stands for escape \
character.

 - What is the meaning of A(?: at start of regex
 - Why there is a / at start
 -What is the meaning of \\z/i at final of regex

All of those because (always I think) because the preg_match()
function is used for re checking. So a perl like syntax should be
used.

Bye
Davide





--~--~-~--~~~---~--~~
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: Understanding validator regex

2007-05-31 Thread Floyd

Thx Davide,

I don't think the double slash escapes \ character, so wouldn't be a
valid email.

The second part, I don't understand the relationship preg_match
function with these symbols. I used this function correctly without
these some times.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Understanding model associations and the view.

2006-12-13 Thread Tazz

I started going through the tutorials and everything is fine. I can
enter data in the databse and display it. Now I would like to create an
association and display it.

But I get the following erro in my view: Warning: Invalid argument
supplied for foreach() in
/www/docs/ads.infected-rhythms.com/inbeat/app/views/albums/index.thtml
on line 15

If I unbind before calling findAll() my view is ok again.

To get an idea here is the link:
http://ads.infected-rhythms.com/inbeat/albums

Bassically here is the data model...

I have record albums and each record album has 1 genre associated to
it...

/*** tables **/

CREATE TABLE albums
(
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(100) NOT NULL,
genre_id INT  NOT NULL,
);

CREATE TABLE genres
(
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(20) NOT NULL
);

/*** models **/

class Album extends AppModel
{
var $name = 'Album';

var $hasOne = array('Genre' =
array('className'= 'Genre',
'conditions'   = '',
'order'= '',
'dependent'=  false,
'foreignKey'   = 'genre_id'
)
);

}

class Genre extends AppModel
{
var $name = 'Genre';
}

/*** controller **/

class AlbumsController extends AppController
{
var $name = 'Albums';

function index()
{
   // Put 1 att the end for recursive fetch.
   // If I use unbind here then I get no error, but then I
canot join to my genre table.
  $this-set('albums', $this-Album-findAll(null, null, null,
null, null, 1));
}
}

/*** view **/

?php foreach ($albums as $album): ?
tr
td?php echo $album['Album']['title']; ?/td
td?php echo $album['Album']['description']; ?/td
td?php echo $album['Album']['genre_id']; ?/td
td?php echo $album['Album']['release_type']; ?/td
td?php echo $album['Album']['essential']; ?/td
td?php echo $album['Album']['created']; ?/td
/tr
?php endforeach; ?

Can anyone see what i'm doing wrong with my view? Thanks!


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---



understanding bake.php

2006-11-16 Thread gazzur

Hi all,
I'm a cake noob. I've been thru the blog tutorial, and understand
scaffolding, but I'm finding it difficult to see how to use bake.php
correctly. As an example, after completing the blog tutorial I deleted
the post model/view/controller pages I created, and kept the database.
I then ran bake.php with the -app example app name command. This
produced a folder similar to the original app folder, with the new
name. I then navigate to this folder in the browser and get the 'sweet,
project baked' message. But it seems that what I don't get, is a baked
copy of the 'posts' blog app, or anything based on the database or
scaffold I used for it.

It seems to be doing what it should - not throwing any errors, so
perhaps I'm not navigating to the correct place, or it's not even
supposed to be doing what I think. If someone could explain, I'd
appreciate it.


--~--~-~--~~~---~--~~
 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: Not quite understanding associations

2006-11-14 Thread hydra12

To do HABTM, you need an extra table.  To do HABTM between users and
game_pieces, you'd need a table called game_pieces_users (table1_table2
in alphabetical order).  game_pieces_users would have 2 fields:
game_piece_id and user_id.

I hope that helps a little.  I've found that scaffolding helps me get a
better idea of how my associations work.  Turn scaffolding on, set some
associations, and then see what info shows up in my view.  It's a
quick, easy way to get visuals on your associations.

hydra12

On Nov 13, 8:59 pm, Christoph [EMAIL PROTECTED] wrote:
 I have the following tables:

 users
 collections, FK user_id, FK game_piece_id
 game_pieces, FK games_set_id
 games_sets, FK game_id, FK set_id
 games
 sets

 So, if I understand correctly:

 users $hasMany collections
 collections $belongsTo users, game_pieces
 game_pieces $belongsTo game_sets
 games_sets $belongsTo games, sets
 games $hasMany games_sets
 sets $hasMany games_sets

 I would think that collections $hasMany game_pieces (such that many
 game pieces make up a collection), but using the relationship between
 users and collections as, well, a model, that means since collections
 belongs to users, it must also belong to game_pieces.

 I suppose collections is a HABTM joining table between users and
 game_pieces?  But if I try to define the association that way, I get an
 error from cake (using the debug mode 3) showing:

 1146: Table 'cake_communal_haven.collections_users' doesn't exist
 1146: Table 'cake_communal_haven.collections_game_pieces' doesn't exist

 so obviously I can't make it a HABTM association.  So I'm just not
 quite getting this...
 
 Any help would be greatly appreciated!
 
 thnx,
 Christoph


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---



Not quite understanding associations

2006-11-13 Thread Christoph

I have the following tables:

users
collections, FK user_id, FK game_piece_id
game_pieces, FK games_set_id
games_sets, FK game_id, FK set_id
games
sets

So, if I understand correctly:

users $hasMany collections
collections $belongsTo users, game_pieces
game_pieces $belongsTo game_sets
games_sets $belongsTo games, sets
games $hasMany games_sets
sets $hasMany games_sets

I would think that collections $hasMany game_pieces (such that many
game pieces make up a collection), but using the relationship between
users and collections as, well, a model, that means since collections
belongs to users, it must also belong to game_pieces.

I suppose collections is a HABTM joining table between users and
game_pieces?  But if I try to define the association that way, I get an
error from cake (using the debug mode 3) showing:

1146: Table 'cake_communal_haven.collections_users' doesn't exist
1146: Table 'cake_communal_haven.collections_game_pieces' doesn't exist

so obviously I can't make it a HABTM association.  So I'm just not
quite getting this...

Any help would be greatly appreciated!

thnx,
Christoph


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---



Difficulty understanding requestAction

2006-10-12 Thread joel

Can somebody help me with requestAction()?  I'm trying to use it
exactly like it's used in the manual, but it's not working for me.  In
my PagesController, I want to generate a list of cities from my
CityController.  Here's what I'm doing:

// in PagesController
function contact() {
  $this-set('cities', $this-requestAction('/cities/getCities'));
}

// in CitiesController
function getCities() {
  return $this-City-generateList();
}

When I do this, nothing is returned.  The $cities variable is empty in
the /pages/contact.thtml view.  Got any ideas?


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Difficulty understanding requestAction

2006-10-12 Thread Drex

Hi,

I remember having the same problem when playing with cake. If I am not
wrong you have to return the value explicitly in the requested action.

regards, dp


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Trouble understanding routes URLs

2006-06-29 Thread hugeLH61

I have done the mollio template tutorial and that is the way I want to
go for my first cake app.
http://wiki.cakephp.org/tutorials:building_a_cakephp_site_part_-_2
But I do not understand how to set up templates/routes for other pages
I add to the menu. Can anyone please shed light?

I have tried routes thus:

#   $Route-connect('/', array('controller' = 'pages', 'action' =
'display', 'home'));
$Route-connect ('/', array('controller'='templates',
'action'='index'));
#   $Route-connect('/pages/*', array('controller' = 'pages', 'action'
= 'display'));
#   $Route-connect('/templates/*', array('controller' = 'templates',
'action' = 'display'));
$Route-connect('/pages/*', array('controller' = 'templates',
'action' = 'display'));

And in the menu nav.thtml I have put a link to my next page
li class=firsta href=templates/testTest/a/li

which when I click menu item 'test' gives me the page Ok, but with URL.
http://localhost/app/templates/test

If I put in the menu
li class=firsta href=testTest/a/li
I get this:
http://localhost/app/test
Missing controller - ie it is not using the templates I think.

How do I get the URL correct? Or should I be routing this differently?

Hugh


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Understanding

2006-06-20 Thread Repsah
You can access the POST data from your controller at$this-dataAs you can see from your pastes the $this-data array contains the values you posted from your form. I assume you have a Post model.
So, if you wanted to access your data, all you need to do is access the $this-data array$this-data['Post']['id'] will hold the id of your post.If the submission already contains the values you want to use to update your DB row all you need to do is a call to
$this-Post-save($this-data);On 6/20/06, [EMAIL PROTECTED] 
[EMAIL PROTECTED] wrote:Thanks to everyone in advance. I am trying to load a specific field
from a table based upon a specific id # (primary key) into a text box.Upon submissions i want to update that specific field based upon thatspecific id#. What i am not understanding is how to get the data after
the post. It seems like after post it creates a new array called[form]?? How do i access this and line up the data to save it?Thanks againBEFORE FORM POST([controller] = post
[action] = edit[pass] = Array([0] = 1)[form] = Array()[url] = Array([url] = /post/edit/1
)[bare] = 0[webservices] =[data] = Array([Post] = Array([id] = 1[title] = 
[body] = [created] = 2006-06-15 21:54:22[modified] = 2006-06-19 23:56:42)))
After FORM POST([controller] = post[action] = edit[form] = Array([data] = Array([Post] = Array
([id] = 1[title] = [body] = qqq)
))[data] = Array([Post] = Array([id] = 1[title] = 
[body] = qqq))[url] = Array([url] = /post/edit)[bare] = 0[webservices] =
)
--~--~-~--~~~---~--~~
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  -~--~~~~--~~--~--~---


Re: Understanding

2006-06-20 Thread [EMAIL PROTECTED]

ok- so how does save() know to to save to the post table and save the
title and body fields for a specific id?

I dont understand the abstraction for getting data from a form into the
database and then displaying whats in the database in the view again.

One thing i should mention is- i am pulling specific rows based upon
the id and updating a specific field in that row with data from a form.

configuration_id | configuration_title | configuration_key |
configuration_value
-
   1   | Store Name |   STORE_NAME  |   osCommerce
   2   |  E-Mail Address   | EMAILADDRESS |
[EMAIL PROTECTED]
   3   |Store Owner |  STORE_OWNER |Harald
Ponce de Leon

I need to retrieve the configuration title information and config value
for rows 1-3 and display them in the view- when the user posts the form
i need to be able to update the update the config_values for rows 1-3.
Is there a standard way of doing this?



Thanks again


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Understanding

2006-06-20 Thread Olivier Percebois-Garve

Usually in your view file corresponding to the form you'll have 
something like:
?php echo $html-hidden('Post/id'); ?

So the method knows what is the right id. If you wanna to change it u 
can use $this-Model-id = $someintegervalue;

Does this answer your question ?

olivvv

[EMAIL PROTECTED] wrote:
 ok- so how does save() know to to save to the post table and save the
 title and body fields for a specific id?

 I dont understand the abstraction for getting data from a form into the
 database and then displaying whats in the database in the view again.

 One thing i should mention is- i am pulling specific rows based upon
 the id and updating a specific field in that row with data from a form.

 configuration_id | configuration_title | configuration_key |
 configuration_value
 -
1 | Store Name |   STORE_NAME  |   
 osCommerce
2 |  E-Mail Address   | EMAILADDRESS |
 [EMAIL PROTECTED]
3 |Store Owner |  STORE_OWNER |Harald
 Ponce de Leon

 I need to retrieve the configuration title information and config value
 for rows 1-3 and display them in the view- when the user posts the form
 i need to be able to update the update the config_values for rows 1-3.
 Is there a standard way of doing this?



 Thanks again


 

   


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Understanding

2006-06-20 Thread [EMAIL PROTECTED]

Thanks in advance-

Ok- i got that part, but what happens when you are displaying multiple
records on one page?
for instance how do i save to multiple specified rows in one post?


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



understanding models

2006-05-24 Thread kain

hi.
I've this:

// app/models/post.php
class Post extends AppModel {
var $name = 'Post';
var $belongsTo = 'State, Region, Province, City, User, Contract,
Tipology, Category';
}

and

// app/models/region.php
class Region extends AppModel {
var $name = 'Region';
var $belongsTo = 'State';
}

when calling $this-Region-findAll(); from controller I have the
expected results:
Array
(
[0] = Array
(
[Region] = Array
(
[id] = ABR
[name] = ABRUZZO
[code] = 13
[state_id] = IT
[superficie] = 10.794 km²
[abitanti] = 1.300.000
[densita] = 120 ab./km²
[city_id] = 49
)

[State] = Array
(
[id] = IT
[name] = ITALIA
)

)
and so on, Region is linked to State model.
I only use belongsTo for my model, but now I need extra functionality.

I need to have the number of posts for each region, posts table
contains a region_id field.
is that possible? any hints how to configure relationships between
these tables?
thanks.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: understanding models

2006-05-24 Thread gwoo

Region hasMany Posts

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Help understanding sessions

2006-05-14 Thread Langdon Stevenson

Thanks for the link AD7six.  Good article that helps highlight the risks 
involved.

I think that it also adds weight to the argument for developing a strong 
authentication module for Cake.  Rolling your own is fine if you know 
what you are doing, but this article has pointed out the weaknesses in 
the authentication system I am using.

Regards,
Langdon


AD7six wrote:
 Hi GregL,
 
 I think all you would need is a 'remember me' cookie to do what you are
 thinking about, there isn't anything complex about doing this as far as
 I can see - set a cookie with the username and password (encrypted) and
 check for the presence of the cookie when doing authentication.
 
 As for security, if you google for session security you'll get plenty
 of results and explenations. However, if you consider having session
 time outs of 1 month for your online bank account - it should be quite
 apparent why sessions have security implicaitons ;) Here's the first
 result I found: http://shiflett.org/articles/security-corner-feb2004
 
 Cheers,
 AD7six

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Help understanding sessions

2006-05-14 Thread GregL

Thanks for the link, that was very illuminating. It highlights my
ignorance on one point: the relationship between a session and a
cookie. I thought they were coupled, that the login info I want to
store was stored in the session which was implemented as a cookie.
Can I have the login info in a cookie of its own, and turn up security
to high and have secure sessions with a one-month login cookie, and
feel safe about it?


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---