Re: HABTM not saving multi-select
My problem has been resolved, thanks to shepardweb.com for providing a very detailed tutorial even I could follow. If you're having problems, visit this link first - you'll save yourself loads of time and frustration. http://www.shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/ However, this didn't get me all the way to my solution. I had to apply the array_keys() function to filter out the names from my selected list. If you've implemented the solution from the link above, and your select list still won't highlight it's default links selectTag is probably getting an id/name pair where it's only expecting ids. $html-selectTag('Computer/Computer', $computers,array_keys($selected_computers),array('multiple' = 'multiple')); A final problem I ran into (and this was a ball-buster) is described in this post (secret 1). http://groups.google.com/group/cake-php/browse_thread/thread/b8816db7ff5854bc My form would submit without error but never bother to update my join table with the new data. According to the link above, you can't have your HABTM multi-select as the top element in your form, or you have to re-order the array before saving in your controller so that the results array starts with the controller-specific data and then finishes with the HATBM data. This is a bug in cakePHP should be fixed. Hope this helps somebody - sure would've saved me some time if I had found it earlier. Steve On Mar 21, 3:41 pm, stevenoone [EMAIL PROTECTED] wrote: I'm sure for some people the Cake approach makes perfect sense and I don't doubt that this framework, when used by someone who understands it well, can dramatically speed development time. Unfortunately there's people like myself for whom much of this is new, and it's not unreasonable for us to be frustrated by nuances we haven't yet wrapped our brains around. Everyone's experience learning this framework is going to be unique based on their programming background and familiarity with MVC concepts. It's wonderful that individuals are volunteering their time to help others get started, but it seems like sometimes that help consists of handwaving half-answers and links to other semi-related threads. Most of us aren't idiots and we wouldn't be posting questions if we hadn't tried to come up with the answers ourselves. If you don't want to help in this forum - don't. If you're tired of answering the same questions, provide good documentation or some well-commented sample apps and let us pick through the code. This blame the user for being confused attitude in some of these posts and evident in the essay linked above doesn't help anybody. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: HABTM not saving multi-select
If anyone's interested, here's the bug report that was in the tracker for the array-order problem. https://trac.cakephp.org/ticket/1819 Hopefully this thread hasn't wasted too much of anyone's time! sn --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: HABTM not saving multi-select
I just noticed I don't have foreign keys set up on my computers_serials table - is this required for cakePHP to understand HABTM relationships? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: HABTM not saving multi-select
Bumping up the debug level, it looks like it's running the correct join: SELECT `Computer`.`id`, `Computer`.`employee_id`, `Computer`.`pc_model_id`, `Computer`.`protection_plan`, `Computer`.`asset_tag_no`, `Computer`.`profiler_dump` FROM `computers` AS `Computer` JOIN `computers_serials` ON `computers_serials`.`serial_id` = '3' AND `computers_serials`.`computer_id` = `Computer`.`id` WHERE 1 = 1 but I'm not asking for the results correctly. Here's what I'm using in edit.thtml $html-selectTag ('Computer/Serial', $computers, $html-tagValue('Serials/computer_id'), array('multiple' = 'multiple')) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: HABTM not saving multi-select
If I can't get this to work I'm going to have to abandon this framework. I've been developing dynamic websites for 10 years, but apparently this is just beyond me. I can't seem to get my multi-select lists to auto-populate correctly or update changes in the database. To get the auto-populate values I'm trying this in my serials_controller $this-set('mycomps', $this-Serial-query(SELECT computer_id FROM computers_serials WHERE serial_id = $this-Serial)); and this in my edit.thtml $html-selectTag('Serial/Computer',$computer_options, $mycomps,array('multiple' = 'multiple')); it isn't working and I don't know why. If i hard-code WHERE serial_id = 1 in the query it returns this array, but I don't see how to fit that into my selectTag. Array ( [0] = Array ( [computers_serials] = Array ( [computer_id] = 2 ) ) [1] = Array ( [computers_serials] = Array ( [computer_id] = 5 ) ) ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: HABTM not saving multi-select
I appreciate the response and the link and I understand that it's frustrating when you feel like you're answering the same question over and over again. Maybe one of the reasons this HABTM of question is getting asked so frequently is that nobody's provided a really good, definitive answer of how this works with clear example code for our models, views, and controllers. I realize the onus is on us beginners to educate ourselves, and maybe I'm an idiot who can't type five letters in a search box, but I'm obviously not the only person who's running into problems with this. Thanks for your help. On Mar 21, 11:44 am, nate [EMAIL PROTECTED] wrote: Hi stevenoone, I'm afraid you'll have to forgive my frustration, as we've had a lot of problems with this lately, but if you abandon this framework out of an inability to enter a search query into the text box in the upper right-hand corner of the page, then I can't say I'll be sorry to see you go. This exact question has already been answered here more times than I care to count. http://groups.google.com/group/cake-php/browse_thread/thread/1bf118d0... On Mar 21, 2:03 pm, stevenoone [EMAIL PROTECTED] wrote: If I can't get this to work I'm going to have to abandon this framework. I've been developing dynamic websites for 10 years, but apparently this is just beyond me. I can't seem to get my multi-select lists to auto-populate correctly or update changes in the database. To get the auto-populate values I'm trying this in my serials_controller $this-set('mycomps', $this-Serial-query(SELECT computer_id FROM computers_serials WHERE serial_id = $this-Serial)); and this in my edit.thtml $html-selectTag('Serial/Computer',$computer_options, $mycomps,array('multiple' = 'multiple')); it isn't working and I don't know why. If i hard-code WHERE serial_id = 1 in the query it returns this array, but I don't see how to fit that into my selectTag. Array ( [0] = Array ( [computers_serials] = Array ( [computer_id] = 2 ) ) [1] = Array ( [computers_serials] = Array ( [computer_id] = 5 ) ) ) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Looking for real-world example apps
Can anyone point me to a few complete, well-commented example applications on CakeForge? I'm basically looking for guidance best practices when it comes to developing apps that go beyond the simple blog tutorial. Personally, I learn better from following real-world examples than from reading reference documentation (although that's important too). I'll be happy to post my software serial number tracker app for others to review and learn from when I've got it to a working state. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
HABTM not saving multi-select
I'm trying to set up a relationship where a serial number can be used on multiple computers and computers can have multiple serial numbers. I have a computers_serials table with computer_id and serial_id columns. In my Computers model I have var $hasAndBelongsToMany = 'Serial'; and in my Serials model I have var $hasAndBelongsToMany = 'Computer';. In my Serials controller I'm getting a list of computers via $this-set('computers', $this-Serial-Computer- generateList()); and populating a multi-select in my serials \edit.thtml with $html-selectTag('Serial/Computer', $computers, null, array('multiple' = 'multiple')). My edit view doesn't read the initial selection state of the multi- select from computers_serials or insert data back into that same table on save. It also doesn't throw an error. I know I'm missing something but I can't figure out what. I've seen a lot of discussion about this in the archives, and I've come to understand that if implemented correctly, Cake should be able to manage these relationships fairly automatically. I'd appreciate any help I can get. sn --~--~-~--~~~---~--~~ 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: afterFind model problem
*bump* 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?hl=en -~--~~~~--~~--~--~---
Re: Menu element
I've added this code to my app_controller and changed it to reflect my data model (my table is called controls instead of categories). Now I get the following errors on every page: Notice: Undefined property: AppController::$Control in /Library/ WebServer/Documents/serials/app/app_controller.php on line 48 Fatal error: Call to a member function generateList() on a non-object in /Library/WebServer/Documents/serials/app/app_controller.php on line 48 What am I missing? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Navigation element
I'm trying to create a dynamic reusable navigation element that I can call where I need it, including from static pages. My menu items are stored in a table called controls with columns for name, path, id and display_order. I'd like to do this the correct cakePHP way instead of writing a verbose database query output loop. I'd appreciate any help I can get. 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 -~--~~~~--~~--~--~---
Re: Navigation element
I tried this solution and whaddya know: if worked! here's my code. //invoke menu element ?php echo $this-renderElement('menu'); ? //menu.thtml ul ?php $controls = $this-requestAction('controls/navindex'); foreach($controls as $control) { print li; if ($control['Control']['path'] == $this-here){ echo $html-link($control['Control']['name'],$control['Control'] ['path'],'class=active'); }else{ echo $html-link($control['Control']['name'],$control['Control'] ['path']); } print /li; } ? /ul On Mar 19, 5:19 pm, gwoo [EMAIL PROTECTED] wrote: This has come up a lot lately for some reason. I guess because there are not enough examples. Personally, I would setup and element. Lets calll it /app/views/ elements/menu.thtml add to this: $controls = $this-requestAction('controls/index'); foreach($controls as $control) { //do whatever} very simply this asks the controls controller to return the index method so you can display the data however you want ?php class ContolsController extends AppController { function index() { $contols = $this-Control-findAll(); //here is where the requesAction is handled so only the data is returned if(isset($this-params['requested'])) { return $controls; } $this-set('controls', $controls); } } ? --~--~-~--~~~---~--~~ 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: afterFind model problem
Fixed with this, but my god it's ugly. ?php class Employee extends AppModel { var $name = 'Employee'; function afterFind($results) { foreach ($results as $key = $val) { if($_SERVER['REQUEST_URI'] == '/employees/') { } else { $results[$key]['Employee']['name_ext'] = $val['Employee']['name'] . ', ' . $val['Employee']['extension']; } } return ($results); } } ? --~--~-~--~~~---~--~~ 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: afterFind model problem
And it just keeps getting worse... help please. ?php class Employee extends AppModel { var $name = 'Employee'; function afterFind($results) { foreach ($results as $key = $val) { if($_SERVER['REQUEST_URI'] == '/employees/'|$_SERVER['REQUEST_URI'] == '/employees/index') { } else { $results[$key]['Employee']['name_ext'] = $val['Employee']['name'] . ', ' . $val['Employee']['extension']; } } return ($results); } } ? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
afterFind model problem
I'm trying to combine two fields (name extension) for display in a computer inventory list. This works when I view my index of computers, but throws an error when i view the index of employees. I'm using this code in my employee model: ?php class Employee extends AppModel { var $name = 'Employee'; function afterFind($results) { foreach ($results as $key = $val) { $results[$key]['Employee']['name_ext'] = $val['Employee']['name'] . ', ' . $val['Employee']['extension']; } return ($results); } } ? This is the error I get when I go to http://localhost/employees/ Notice: Undefined index: Employee in C:\wamp\www\app\models \employee.php on line 11 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---