Table join confusion...
I need a little assistance with a join over 3 tables. I have the following Models (User > Profile > Infogroup > Information): - User (hasMany Profile) - Profile (belongsTo User, hasMany Infogroup) - Infogroup (belongsTo Profile, hasMany Information) - Information (belongsTo Infogroup) The relationships are defined in the model classes, and there is no problem getting the associated data, when for example fetching a User. However, what do I need to do to get all Information that belongs to a specific User? I.e. all rows from the informations table "where Information.infogroup_id = Infogroup_id AND Infogroup.profile_id = Profile.id AND Profile.user_id = XYZ"? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Auth component + extra variables
Hello I have a login procedure that requires more information than just the username and password. Controller: "employees" Action: "login" Databasefields needed for login: email, password, group (because it is possible to have the same email for different groups). Login URL: http://mydomain.com/login/group1 When someone makes a failed login attempt, he is redirected to http://mydomain.com/login instead of http://mydomain.com/login/group1. How can I make the Auth component redirect the user to .../login/ group1? ("group1" is a variable, it could be anything, which is checked against the DB) --~--~-~--~~~---~--~~ 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: saveAll() with $fieldList problem
Hi Joshua. Thanks for your response, but unfortunately you misunderstood the issue. I am NOT asking for the format of the $data array, but the $fieldList (an option that can be passed on to the saveAll() function). According to the CakePHP docs (your link): "If $fieldList is not supplied, a malicious user can add additional fields to the form data, and by this change fields that were not originally intended to be changed." Now, passing an Array like below to $this->User->save($data, $fieldList) is fine: $fieldList = array( 'first_name', 'last_name', ); QUESTION: How about saveAll() with multiple Models (like in my example in the first post)? How should the $fieldList array look? On Jul 13, 4:50 am, joshua wrote: > > Take a look at the chapter ' 3.7.4 Saving Your > > Data<http://book.cakephp.org/view/75/Saving-Your-Data#Saving-Related-Model...>' > > in cakebook. > > Array > ( > [Article] => Array > ( > [title] => My first article > ) > [Comment] => Array > ( > [0] => Array > ( > [comment] => Comment 1 > [user_id] => 1 > ) > [1] => Array > ( > [comment] => Comment 2 > [user_id] => 2 > ) > ) > ) > > $this->Article->saveAll($data); > > > > > > On Mon, Jul 13, 2009 at 4:34 AM, jakobjp wrote: > > > I cannot get the $fieldList to work for Model->saveAll() not matter > > what I try. > > > How should the $fieldList array be formatted when storing a Model plus > > associated Models via saveAll()? > > > My example: > > > Form fields: > > User.first_name > > User.last_name > > Address.street > > Address.city > > ... > > > The two models User and Adresse are associated with the User "hasOne" > > Address. > > -- > Thanks > Joshua > 5span Inc. <https://www.5span.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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
saveAll() with $fieldList problem
I cannot get the $fieldList to work for Model->saveAll() not matter what I try. How should the $fieldList array be formatted when storing a Model plus associated Models via saveAll()? My example: Form fields: User.first_name User.last_name Address.street Address.city ... The two models User and Adresse are associated with the User "hasOne" Address. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
AuthComponent: Not logged in VS. Not authorized
It seems to me, that if you're not logged in OR if you are not authorized for a specific action, you will receive the same message ($this->Auth->authError in the Controller). I would, however, prefer two different messages. I.e. "Please login" if not logged in at all, or "Not authorized" if logged in, but not authorized. How could this be accomplished? --~--~-~--~~~---~--~~ 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: Aggregating child field
I suspect this to be a pretty common thing to do, so I hope someone can let me know how ;-) On May 24, 11:22 pm, Teh Treag wrote: > jakobip, > > What do you have $this->Event->recursive set to? Are the associations > done correctly? > > -teh > > On May 24, 9:12 am,jakobjp wrote: > > > > > Hmm, I'm not sure I follow the example. At least it didn't help we to > > resolve this - probably because of lacking skills on my part :-( > > > When I add the following afterFind() function to my Event method... > > > function afterFind($events) { > > foreach ($events AS $event) { > > pr($event); > > } > > > } > > > ... I would expect the outputted Event array to hold a sub-array > > containing it's related Tickets. However, that's not the case. It just > > looks like this (no sign of the Tickets): > > > Array > > ( > > [Event] => Array > > ( > > [id] => 2 > > [user_id] => 7 > > [title] => Testevent > > [created] => 2009-05-24 12:51:32 > > [updated] => 2009-05-24 12:51:32 > > ) > > ) > > > How do I get access to the Tickets, so I can perform a calculation on > > the "price" field (i.e. generate the Event.total_ticket_price value)? > > And, wouldn't it be better for performance to include the > > Event.total_ticket_price value directly in the SQL query somehow? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Auth and fieldList
Im having a problem with the $fieldList parameter for my User model's save() method: (in users_controller) $this->data['User']['password_confirm_hashed'] = $this->Auth->password ($this->data['User']['confirm_password']); $fieldList = array( 'first_name', 'last_name', 'email', 'password', 'password_confirm', 'password_confirm_hashed', ); if ($this->User->save($this->data, true, $fieldList)) { $this->__sendActivationEmail($this->User->getLastInsertID()); $this->redirect('/thank_you'); } I use the fieldList for the save() method to limit the save to the actual fields being asked for in the signup process, to avoid the user from adding values to other fields by modifying the form (for example there is a "activated" field in the users table, that indicated that the user has clicked the activation link in an email he receives after signup). My problem: As soon as I add the "true" for validation and $fieldList array to the save method, then the password_confirm check is no longer applied! I know the password confirm check works just fine, because the simply running $this->User->save($this->data) works like a charm. As soon as I run $this->User->save($this->data, true, $fieldList) then the validation for confirm_password (and only for that, not for the other fields) is ignored! Why does that happen? --~--~-~--~~~---~--~~ 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: Objects vs. arrays
Thanks for your help guys :-) On May 24, 7:34 pm, mark_story wrote: > You can still do this with models as well. Using read(), create(), > and set() your model methods can access the 'active record' and > manipulate it. so for example > > $this->Apple->id = 1; > $this->Apple->read() > if ($this->Apple->isRed()) { > //do something > > } > > And your isRed method could look like > > function isRed($color = null) { > if (!$color && isset($this->data['Apple']['red'])) { > $color = $this->data['Apple']['color']; > } > return $colour == 'red'; > > } > > -Mark > > On May 23, 9:59 am, jakobjp wrote: > > > > > I've read a few discussions about CakePHP returning objects vs. > > arrays, and this is NOT intended to be such. I just have a question, > > related to it: > > > I used to have (i.e. "before CakePHP") objects like this: > > > class Apple { > > var $color; > > var $sweet; > > function __construct($id = false) { > > if ($id) $this->load($id); > > return $this; > > } > > function load($id) { > > ... do something to load apple with `id` = $id from db ... > > } > > function isRed() { > > if ($this->color == 'red') return true; > > else return false; > > } > > > } > > > In my code I would then often work like this: > > > $apple = new Apple(123); > > if ($apple->isRed()) echo 'Apple is red"; > > else echo 'Apple is not red'; > > > Now my question: > > Where would a function like isRed() be located in the the CakePHP-way? > > > Since in Cake I don't have an object to call a model's method on, I am > > not sure how to go about this... --~--~-~--~~~---~--~~ 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: Aggregating child field
Hmm, I'm not sure I follow the example. At least it didn't help we to resolve this - probably because of lacking skills on my part :-( When I add the following afterFind() function to my Event method... function afterFind($events) { foreach ($events AS $event) { pr($event); } } ... I would expect the outputted Event array to hold a sub-array containing it's related Tickets. However, that's not the case. It just looks like this (no sign of the Tickets): Array ( [Event] => Array ( [id] => 2 [user_id] => 7 [title] => Testevent [created] => 2009-05-24 12:51:32 [updated] => 2009-05-24 12:51:32 ) ) How do I get access to the Tickets, so I can perform a calculation on the "price" field (i.e. generate the Event.total_ticket_price value)? And, wouldn't it be better for performance to include the Event.total_ticket_price value directly in the SQL query somehow? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Aggregating child field
I have a model Event that hasMany Ticket. Ticket has a field called "price". I would like to accomplish that Event gets an attribute "total_ticket_price", which is the sum of "price" for all of Event's Tickets. I have been trying to looking into the afterFind() method, but I have been unable to accomplish this. Your help is much appreciated. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Objects vs. arrays
I've read a few discussions about CakePHP returning objects vs. arrays, and this is NOT intended to be such. I just have a question, related to it: I used to have (i.e. "before CakePHP") objects like this: class Apple { var $color; var $sweet; function __construct($id = false) { if ($id) $this->load($id); return $this; } function load($id) { ... do something to load apple with `id` = $id from db ... } function isRed() { if ($this->color == 'red') return true; else return false; } } In my code I would then often work like this: $apple = new Apple(123); if ($apple->isRed()) echo 'Apple is red"; else echo 'Apple is not red'; Now my question: Where would a function like isRed() be located in the the CakePHP-way? Since in Cake I don't have an object to call a model's method on, I am not sure how to go about this... --~--~-~--~~~---~--~~ 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: Map model attributes to different database fields
Some of the reasons are: 1) Users can use the old version during a transition period, so they are not forced to switch to the new version for convenience, and 2) (important) a lot of backend-services (mostly some php scripts executed as cron jobs) run with old code (and php objects) and cannot just be "transformed". I believe this should be a fairly common problem for projects developed in CakePHP that have previously been developed with (or without) something else, and cannot just change the database structure like that... I found a behavior that seems to accomplish this (almost), but I really don't understand why you cannot define this in the models like: class User extends AppModel { var $_schema = array( 'attribute_name' => array('name'=>'field_name', 'type'=> 'string' ... ) ); } Attribute_name would be used in the code, while field_name is the real database table field. An example select query would be: SELECT field_name AS attribute_name ... This functionality shouldn't be rocket science IMHO, but maybe I'm mistaken, and it's more complex than it seems? On Apr 20, 6:53 pm, brian wrote: > I suppose the burning question is, why do you want both versions of > the app using the same DB? That seems fraught with peril. > > > > On Mon, Apr 20, 2009 at 11:03 AM, jakobjp wrote: > > > I am trying to map model attributes to database fields with different > > names. > > > Example of regular CakePHP model: > > User Model with attributes "id" and "firstname" would load the > > appropriate values from same-named database fields "id" and > > "firstname". > > > Example of my CakePHP mode: > > User Model with aatributes "id" and "first_name" should load the > > appropriate values from the fields "uid" and "firstname". > > > I know this is not perfect, but absolutely necessary because the new > > and old application will use the existing database at the same time. > > However, we do not want to continue using the old attribute names like > > "uid" and "firstname". > > > I've tried playing around with the $_schema variable, but with no > > luck :-( > > > Summary of this question: How to load a model attribute called X from > > a database table field called Y? > > > Your help is much appreciated. --~--~-~--~~~---~--~~ 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: Map model attributes to different database fields
Another way of describing the problem is that instead of having the following query style: SELECT uid, firstname FROM users; I want this query style: SELECT uid AS id, firstname AS first_name FROM users; So that I can use the attributes "id" and "first_name" in the code, but it will work with the data from "uid" and "firstname". --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Map model attributes to different database fields
I am trying to map model attributes to database fields with different names. Example of regular CakePHP model: User Model with attributes "id" and "firstname" would load the appropriate values from same-named database fields "id" and "firstname". Example of my CakePHP mode: User Model with aatributes "id" and "first_name" should load the appropriate values from the fields "uid" and "firstname". I know this is not perfect, but absolutely necessary because the new and old application will use the existing database at the same time. However, we do not want to continue using the old attribute names like "uid" and "firstname". I've tried playing around with the $_schema variable, but with no luck :-( Summary of this question: How to load a model attribute called X from a database table field called Y? Your help is much appreciated. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
List with aggregated fields
I have a list of articles. One of the columns shows an aggregate field, which is the average rating of the article. Problem: The list only shows articles that have at least one rating. The SQL query generated by CakePHP is not considering articles that have no rating at all. The function in the controller i pretty simple: function index() { $this->Article->bindModel(array( 'hasOne' => array( 'average_rating' => array( 'className' => 'Rating', 'fields' => 'AVG(average_rating.value) AS average_rating' ) ) ), false); $this->set('articles', $this->paginate()); } The SQL query that is executed is (pagination is used, with 5 items per page): SELECT `Article`.`id`, `Article`.`user_id`, `Article`.`title`, `Article`.`text`, `Article`.`finished`, `Article`.`created`, `Article`.`modified`, `User`.`id`, `User`.`first_name`, `User`.`last_name`, `User`.`email`, `User`.`password`, `User`.`activated`, `User`.`created`, `User`.`modified`, AVG (`AvgRating`.`value`) AS AvgRating, AVG(`average_rating`.`value`) AS average_rating FROM `nedito_articles` AS `Article` LEFT JOIN `nedito_users` AS `User` ON (`Article`.`user_id` = `User`.`id`) LEFT JOIN `nedito_ratings` AS `AvgRating` ON (`AvgRating`.`article_id` = `Article`.`id`) LEFT JOIN `nedito_ratings` AS `average_rating` ON (`average_rating`.`article_id` = `Article`.`id`) WHERE 1 = 1 ORDER BY `Article`.`created` desc LIMIT 5 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Advanced relationships (roles on an element basis)
I'm trying to figure out how to create a system that can handle the following: Models: user, post, category Roles: regular, moderator, admin - User ("regular user") can create posts in categories. - User ("regular user") can edit own posts. - Multiple users can have the role "moderator" in multiple categories. - "Moderators" can do the same things as "regular user" and edit posts in categories they are "moderator" for. - Multiple users can have the role "admin" in multiple categories. - "Admins" can do the same things as "moderators", but also delete posts in the category and edit the categories they are "admin" for. Basically each user can be a moderator in one, an admin for another, and a simple user in a third category. This includes roles per element (such as user1 and user7 are "moderator" for category3, while user7 is also "admin" for category9) and inheritance of role-rights (Moderator can do what regular user can do plus something more. Admin can do what moderator can (hence, also what regular can) plus something more). I have tried reading up on tons of material about ACL, but don't seem to get the hang of it... Hope a smart mind here can guide me in the right direction :-) --~--~-~--~~~---~--~~ 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: l10n in cakephp > can't get app to switch language
This is weird: I can successfully change the language with $this- >Session->write('Config.language', 'fr'); in the beforeRender() function in apps_controller.php Why does it not work in beforeFilter()? Does it matter where it's being done? On Mar 10, 2:09 pm, jakobjp wrote: > On Mar 10, 2:25 am, "jitka (poLK)" wrote: > > > > I have created two test languages in: > > > /app/locale/eng/LC_MESSAGES/default.php > > > /app/locale/fre/LC_MESSAGES/default.php > > > php extension is reason. CakePHP assumes there plaintext .po (or > > preferrable binary .mo) files. > > Yeah that was a mistake in my email. The files are already ".po" files > in plaintext. The content is as follows (in the english one): > msgid "test" > msgstr "The Test" > > Both my testing language work fine when setting the language in > core.php, but I can't switch away from the default language in the > application controller. --~--~-~--~~~---~--~~ 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: l10n in cakephp > can't get app to switch language
On Mar 10, 2:25 am, "jitka (poLK)" wrote: > > I have created two test languages in: > > /app/locale/eng/LC_MESSAGES/default.php > > /app/locale/fre/LC_MESSAGES/default.php > > php extension is reason. CakePHP assumes there plaintext .po (or > preferrable binary .mo) files. Yeah that was a mistake in my email. The files are already ".po" files in plaintext. The content is as follows (in the english one): msgid "test" msgstr "The Test" Both my testing language work fine when setting the language in core.php, but I can't switch away from the default language in the application controller. --~--~-~--~~~---~--~~ 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: l10n in cakephp > can't get app to switch language
Unfortunately that didn't do the trick... :-( On Mar 10, 1:42 am, Miles J wrote: > I use app import and it worked for me: > > App::import('Core', 'l10n'); > $l10n = new L10n(); > $l10n->get($locale); > > I also place it in my app controller beforeFilter(). If you are doing > it in another controller, be sure to call parent::beforeFilter() in > that controllers beforeFilter(). --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
l10n in cakephp > can't get app to switch language
've been reading a lot about l10n in cakephp now, but there seems to be some confusion about what is the correct way to use languages... I have created two test languages in: /app/locale/eng/LC_MESSAGES/default.php /app/locale/fre/LC_MESSAGES/default.php I am displaying my test string in a view with __('test') and it displays the value for the english (default language) fine. However, I do not seem to find the right way of changing the language in my application. My /app/controllers/app_controller.php includes the following: I have also tried to change the language using both 'fr' and 'fre' and changing the the beforeFilter() to try with $this->L10n = new L10n(); $this->L10n->get("eng"); instead of Configure::write(Config.language', 'fre'); But that doesn't work either... I've spent 3 hours trying to figure out how to switch the language now... That's frustrating! Hope someone has an idea ;-) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---