I did something simliar like you want to do with the checkboxes with a drop-
down list. I didn't use the searchable-behaviour-for-cakephp but used AJAX
instead.
On top of my search from ctp I includ a JavaScript file:
<script type="text/javascript" src="/ww/js/foodselect.js"></script>
In my search form I have my dropdown:
echo $this->Form->input('category_id', array('onChange' =>
'getFoodByCategory()', 'empty' => '---'));
foodselect.js:
function getFoodByCategory() {
var category_id = document.getElementById('UserpointCategoryId').value;
// alert(category_id);
// alert('/ww/foods/getFoodByCategory/' + category_id);
$.post('/ww/foods/getFoodByCategory/' + category_id, function(data) {
document.getElementById('UserpointFoodIdDiv').innerHTML = data;
});
}
in my foods controller I have the function:
function getFoodByCategory($category_id = null) {
$this->layout='ajax';
$this->Food->recursive = 0;
$this->Food->order = array('Food.name asc');
$param = array( 'conditions' => array('Food.category_id' =>
$category_id)); $foodall = $this->Food->find('all',$param);
foreach ($foodall as $food){
$li[$food['Food']['id']] = $food['Food']['name'].' ('.
$food['Food']['points'].' Punkte)';
}
$this->set('foods',$li);
}
This together fills my another dropdown with my food selection, but you can
also have a div filles with an index table, depending what you want.
the output is formatted in the file /views/foods/get_food_by_category.ctp
In my case it creates the dropdown:
<?php
//debug($foods);
echo '<select name="data[Userpoint][food_id]" id="UserpointFoodId">';
foreach($foods as $key => $value){
echo utf8_decode ( '<option value="'.$key.'">'.$value.'</option>');
}
echo '</select>';
?>
In Javascript a dropdown is easier to handle than checkboxes, as you might
know, but they should also work.
Hoep that example helps
Anja
Am Donnerstag, 24. Februar 2011, um 20:13:03 schrieb MeatSandwich:
> 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 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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment