To start I have it im app_model so I can use it anywhere. I think I said plugin last night but looks like I never ended up converting it into one.
Delete the Cache::lines if you like for now: $alpha_links = array(); foreach(range('A','Z') as $i): $params = array( 'conditions' => array( $this->alias.'.search_group' => $i), 'fields' => array( $this->alias.'.title', $this->alias.'.id'), 'contain' => false); if ( $this->find('first', $params) ) { $alpha_links[$i] = 1; } else { $alpha_links[$i] = 0; } endforeach; return $alpha_links; Now since this is untested with the new array keys A, B, C my old helper for this has to be editied so untested off the top of my head: Controller call the function $this->set('alphabet', $this->Product->alpha_paging()); Helper: Just a function to run thru each $alphabet as $letter => $value { //make current link active if ( !empty ($this->params['pass']['0']) && $this->params['pass']['0'] === strtolower($letter)): $selected = "selected"; else:$selected = null; endif; $output .= $this->Html->link( $letter, array( 'action' => 'index', strtolower( $letter ), 'admin' => false) , array( 'escape' => false, 'class' => $selected ),false); else: $output .= $letter; That should get you going. K -----Original Message----- From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of MeatSandwich Sent: Friday, February 25, 2011 8:26 AM To: CakePHP Subject: Re: Search function Hi Krissy, that sounds absolutely perfect for the alphabet part of what I want to do, thank you :) Sorry for being such a noob but could you give me a bit more detail about how to use this code. Does that all go into the users_controller at the end of the add new user action? There are some things I don't recognise in the code which I guess must be something to do with the cache, so I'll have to go off and do a bit of reading! thanks On Feb 25, 9:10 am, "Krissy Masters" <naked.cake.ba...@gmail.com> wrote: > For the Alphabet I made my own custom plugin function that just runs thru > the alphabet and does a query to find each letter. My table has search_group > field which saves the first letter upper / lowercase you decide of whatever > field the alphabet is for (name, business whatever) creates links if a > letter is found if not just a letter is returned. Cache the query so it only > runs 1 time and after a new user / member / product is added delete the > cache and update with a new running of the alpha function. > > public function alpha_paging () { > > $alpha_links = Cache::read('alpha_nav_'. $this->alias, 'short'); > > if (empty($alpha_links ) ) { > $alpha_links = array(); > > foreach(range('A','Z') as $i): > $params = array( > 'conditions' => array( > $this->alias.'.search_group' => $i), > 'fields' => array( > $this->alias.'.title', > $this->alias.'.id'), > 'contain' => false); > > if ( $this->find('first', $params) ) { > $alpha_links[] = 1; > } else { > $alpha_links[] = 0; > } > endforeach; > Cache::write( 'alpha_nav_'. $this->alias, $alpha_links, > 'short' ); > } > return $alpha_links; > > } > > You end up with an array 0 - 25 with each having a bool 0 or 1 if letter was > found. The array is numeric but that does not matter since we know how many > letters there are in the alphabet. > > 0 => 0 // A has no record > 1 => 0 // B has no record > 2 => 1 // C has a record > > _______________________________ > Each array key represents the numeric count of the letter(offset by 1) > 0 => A > 1 => B > .... > 25 => Z > > Hope that gets you started. > > K > > -----Original Message----- > From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf > > Of MeatSandwich > Sent: Thursday, February 24, 2011 3:43 PM > To: CakePHP > Subject: Search function > > Hi all, > > I'm new to cakephp and only know a bit of php so I'm on a steep > learning curve since although I've made websites using php and mysql > before they were all a bit simple. I'm not looking for code here but > some pointers for me so I know what to learn. > > The app I'm making will end up with lots of members and I'd like to > make a search function so people can find other people easily. I've > discovered searchable-behaviour-for-cakephp and hopefully that'll > provide most of what I want but as another way to search rather than a > text box, I'd also like to have the letters of the alphabet so a user > can click and go straight to that letter. > > As well as that, members will say in their profiles what their > favourite animals are, ie cats/dogs/horses etc - they'll have 20 to > choose from. I'd like my search function to have checkboxes > representing each animal and someone who was searching could check the > dogs box and only people who like dogs will be listed, they could then > also check cats box and the members who like dogs and cats will be > shown. If possible I'd like the list to update automatically as each > box is clicked. > > I have everything else set up and only need help with this search > part. Assuming searchable-behaviour-for-cakephp does me for my text > search box, I reckon the alphabet thing will be something like making > a link for each letter and somehow making that link run a query, > hopefully that will work. > > But the checkbox thing that updates automatically I'm not sure about. > Is it ajax I need? Are there any particular methods I should be using? > > -- > Our newest site for the community: CakePHP Video Tutorialshttp://tv.cakephp.org > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd 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 athttp://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 -- 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