Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Is there a good tutorial / instructions for the CakeDC ratings plugin anywhere? I'm 4 hours in and still no end in site - the read-me is useless.
Here is some code that I used to get the ratings plugin working. It is all Ajax, so I added one hack to the RatingHelper to avoid showing a "Rate!" button, just add submit=>false to the options.
if ($options['createForm']) {
if (!empty($options['target']) && !empty($options['createForm']['url']) && !empty($options['createForm']['ajaxOptions'])) {
$ajaxOptions = array_merge(array('url' => $options['createForm']['url']), $options['createForm']['ajaxOptions']);
$result .= $this->Js->submit(__d('ratings', 'Rate!'), $ajaxOptions) . "\n";
$flush = true;
} elseif ( !isset($options['submit']) || !empty($options['submit']) ) {
if(empty($options['submit'])) {
$result .= $this->Form->submit(__d('ratings', 'Rate!')) . "\n";
} else {
$result .= $this->Form->submit($options['submit']) . "\n";
}
}
$result .= $this->Form->end() . "\n";
if ($flush) {
$this->Js->writeBuffer();
}
}
I have an index view that is showing a bunch of car models and I show an overall rating and the current users rating:
<?php foreach ($carmodels as $carmodel): ?>
<tr>
<td><?php echo h($carmodel['Carmodel']['id']); ?> </td>
<td><?php echo h($carmodel['Carmodel']['name']); ?> </td>
<td>
<?php echo $this->Html->link($carmodel['Make']['name'], array('controller' => 'makes', 'action' => 'view', $carmodel['Make']['id'])); ?>
</td>
<td>
<?php $overall_div = 'overall-rating' . $carmodel['Carmodel']['id']; ?>
<div id="<?php echo $overall_div; ?>">
<?php
echo $this->element('rating', array('rating' => $carmodel['Carmodel']['rating']));
?>
</div>
</td>
<td>
<?php
$msg_div = 'rating-msg' . $carmodel['Carmodel']['id'];
$rating = 0;
if (!empty($carmodel['Rating'])) {
$rating = $carmodel['Rating'][0]['value'];
}
echo $this->Rating->display(array(
'item' => $carmodel['Carmodel']['id'],
'type' => 'radio',
'stars' => 5,
'value' => $rating,
'submit' => false,
'createForm' => array(
'id' => 'CarmodelsRatingsDemoForm' . $carmodel['Carmodel']['id'],
'url' => array('action' => 'ratings_update', $carmodel['Carmodel']['id']),
'class' => 'rating',
'update-overall' => '#' . $overall_div,
'update-msg' => '#' . $msg_div,
)));
?>
<div id="<?php echo $msg_div; ?>" class="label label-info hidden">
<button class="close" data-dismiss="alert" type="button">×</button>
<div class="msg-default"><?php echo __('One moment...'); ?></div>
<div class="msg-result"></div>
</div>
</td>
Then I have some Jquery goodness to create the stars and then react on the click
$(document).ready(function(){
$('form.rating').stars({
cancelShow:true,
callback: function(ui, type, new_value) {
var values = ui.$form.serializeArray();
values.push({
'name': 'rating',
'value': new_value
});
values = jQuery.param(values);
var msg = ui.$form.attr('update-msg');
$(msg).removeClass('hidden');
$(msg).show();
$(msg).find('div.msg-default').show();
$(msg).find('div.msg-result').hide();
$.ajax({
'type': 'POST',
'dataType': 'json',
'url': ui.$form.attr('action'),
'data': values
}).done(function(data) {
var overall_rating = ui.$form.attr('update-overall');
if(overall_rating && data['overall_rating']){
$(overall_rating).html(data['overall_rating']);
}
if(msg){
$(msg).find('div.msg-default').hide();
if(data['msg']) {
$(msg).find('div.msg-result').show();
$(msg).find('div.msg-result').html(data['msg']);
window.setTimeout(function() {
$(msg).addClass('hidden');
}, 2000);
} else {
$(msg).addClass('hidden');
}
}
if(data['user_rating'] && data['user_rating']>0) {
ui.select(parseInt(data['user_rating']));
}
});
}
});
})
Plus I need a little snippet of css to hide the radio button labels that Cake adds.
form.rating > div.input {
display: none;
}
Then in the controller, I check if the user has rated the item before and save if not. I return a json array that contains a rendered element of the overall rating, the users rating (new or existing) and a string message to show in a div that disappears after 2 seconds.
public function ratings_update($id = null) {
$this->Carmodel->id = $id;
if (!$this->Carmodel->exists()) {
throw new NotFoundException(__('Invalid carmodel'));
}
$ratings = $this->Carmodel->isRatedBy($id, 1);
if (!$ratings) {
$this->Carmodel->rate($id, 1, $this->request->data['rating'], array('values' => array_combine(range(1, 5), range(1, 5))));
$json['msg'] = __('Thank you');
} else {
if ($this->request->data['rating'] == 0) {
$this->Carmodel->removeRating($id, 1);
$json['msg'] = __('Rating removed');
} else {
$json['msg'] = __('Already rated');
}
}
$this->set('rating', $this->Carmodel->field('rating'));
$ratings = $this->Carmodel->isRatedBy($id, 1);
$my_rating = 0;
if (!empty($ratings)) {
$my_rating = $ratings['Rating']['value'];
}
$this->autoRender = false;
App::uses('View', 'View');
$View = new View($this);
$response = $View->render('/Elements/rating', 'ajax');
$json['overall_rating'] = $response;
$json['user_rating'] = $my_rating;
return json_encode($json);
}
Here is the code for the element that shows stars for the overall rating, it probably should be part of the helper.
if (empty($rating)) {
echo __('Be the first to rate!');
} else {
echo str_repeat('<div class="ui-stars-star ui-stars-star-on"><a title=""></a></div>', $rating);
}
So while that isn't a super-detailed instruction, you should be able to figure out what the code is doing and replicate it. It took me the better part of a day to get it working.
Related
Goodnight (or good morning),
I trying to upload multiple files at the same time. I am following the cookbook instructions to build the solution. I always got first file (not and array of files).
Here is my view code...
<?php
/**
* #var \App\View\AppView $this
* #var \App\Model\Entity\Upload $upload
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Html->link(__('List Uploads'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column-responsive column-80">
<div class="uploads form content">
<?= $this->Form->create($upload, ['type' => 'file']) ?>
<fieldset>
<legend><?= __('Add Upload') ?></legend>
<?php
echo $this->Form->control('name');
echo $this->Form->control('document_type_id', ['options' => $documentTypes]);
echo $this->Form->control('period_id', ['options' => $periods]);
echo $this->Form->control('user_id', ['options' => $users]);
echo $this->Form->control('documents', ['type' => 'file', 'label' => __('Choose PDF Files'), 'accept' => 'application/pdf', 'multiple' => 'multiple']);
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
</div>
</div>
And here is my controller code...
public function add()
{
$upload = $this->Uploads->newEmptyEntity();
if ($this->request->is('post')) {
$upload = $this->Uploads->patchEntity($upload, $this->request->getData());
if ($this->Uploads->save($upload)) {
if (!is_dir($this->Parameters->findByName('document_directory')->first()->toArray()['value'] )) {
mkdir($this->Parameters->findByName('document_directory')->first()->toArray()['value'], 0776, true);
}
$documents = $this->request->getData('documents');
$this->loadModel('Dockets');
$dockets = $this->Dockets->findByDocketStateId(1);
$documents_ok = 0;
$documents_nok = 0;
$dockets_without_document = 0;
foreach($documents as $documents_key => $document_to_save)
{
foreach($dockets as $dockets_key => $docket)
{
$contents = file_get_contents($document_to_save);
$pattern = str_replace('-', '', $pattern);
$pattern = str_replace('', '', $pattern);
$pattern = preg_quote($docket->cuit, '/');
$pattern = "/^.*$pattern.*\$/m";
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){
$documentsTable = $this->getTableLocator()->get('Documents');
$document = $documentsTable->newEmptyEntity();
$document->upload_id = $upload->id;
$document->document_type_id = $upload->document_type_id;
$document->period_id = $upload->period_id;
$document->docket_id = $docket->id;
$document->user_id = $this->getRequest()->getAttribute('identity')['id'];
if ($documentsTable->save($document)) {
if (!is_dir($this->Parameters->findByName('document_directory')->first()->toArray()['value'] )) {
mkdir($this->Parameters->findByName('document_directory')->first()->toArray()['value'], 0776, true);
}
$fileobject = $this->request->getData('document');
$destination = $this->Parameters->findByName('document_directory')->first()->toArray()['value'] . 'document_' . $document->id . '.pdf';
// Existing files with the same name will be replaced.
$fileobject->moveTo($destination);
}
$this->Flash->error(__('The document could not be saved. Please, try again.'));
$documents_ok = $documents_ok + 1;
unset($dockets[$dockets_key]);
unset($documents[$documents_key]);
break;
}
}
}
if(!empty($documents)){
//print_r($documents);
$documents_nok = count($documents);
unset($documents);
}
if(!empty($dockets)){
$dockets_without_document = count($dockets);
unset($dockets);
}
$message = __('There were processed ') . $documents_ok . __(' documents succesfully. ') . $documents_nok . __(' documents did not math with a docket. And ') . $dockets_without_document . __(' active dockets ddid not not have a document.');
$this->Flash->success(__('The upload has been saved. ') . $message);
return $this->redirect(['action' => 'view', $upload->id]);
}
$this->Flash->error(__('The upload could not be saved. Please, try again.'));
}
$documentTypes = $this->Uploads->DocumentTypes->find('list', ['keyField' => 'id',
'valueField' => 'document_type',
'limit' => 200]);
$periods = $this->Uploads->Periods->find('list', ['keyField' => 'id',
'valueField' => 'period',
'limit' => 200]);
$users = $this->Uploads->Users->find('list', ['keyField' => 'id',
'valueField' => 'full_name',
'conditions' => ['id' => $this->getRequest()->getAttribute('identity')['id']],
'limit' => 200]);
$this->set(compact('upload', 'documentTypes', 'periods', 'users'));
}
Can you help me to understand what I doing wrong?
Thanks,
Gonzalo
When using PHP, multi-file form inputs must have a name with [] appended, otherwise PHP isn't able to parse out multiple entries, they will all have the same name, and PHP will simply use the last occurrence of that name.
echo $this->Form->control('documents', [
'type' => 'file',
'label' => __('Choose PDF Files'),
'accept' => 'application/pdf',
'multiple' => 'multiple',
'name' => 'documents[]',
]);
Furthermore the following line:
$fileobject = $this->request->getData('document');
should probably be more like this, as there a) is no document field and b) even if there were, you most likely wouldn't want to process the same file over and over again:
$fileobject = $documents[$documents_key];
Also make sure that you have proper validation in place for the uploaded files, even if you don't seem to use the user provided file information, you should still make sure that you've received valid data!
I'm creating a website using CakePHP. On my main page I want to display the six latest videos and the six most popular videos. I've made an element named 'itemList' that I pass a type parameter and an array with items.
I use the following code for the latest videos:
$this->element('itemList', array('type' => "video", 'items' => $latestVideos));
echo $this->fetch('itemList');
And the following code for the popular videos:
$this->element('itemList', array('type' => "video", 'items' => $popularVideos));
echo $this->fetch('itemList');
The latest videos get displayed just the way they should, but the popular videos first show the latest videos (for the second time) and the popular videos afterwards.
Does anyone know how I can "clear" or "unset" the first itemList element, to start off with an empty one when it gets used for the second time?
<?php
/* The following parameters are set when this element is called upon:
* $type: article, video
* $items: the list with items to be displayed
*/
$this->start('itemList');
echo $this->Html->script('equalColumns');
$itemCount = 0;
$mainType = $type;
$listType = null;
// If the article list is called, use wider columns css (.articleList)
if ($type == "article") {
$listType = " articleList";
}
?>
<ul class="otherArticles<?php print($listType); ?>">
<?php
foreach ($items as $item) {
$duration = null;
$coverImage = null;
$coverImageOffset = array("x" => 0, "y" => 0);
/* If a list of tags is submitted, check for every item if the item is an article or a
* video
*/
if ($mainType == "tag") {
if ($item["TagRelationship"]["article_id"] != null) {
$newItem["Article"]["id"] = $item["TagRelationship"]["article_id"];
$newItem["Article"]["slug"] = $item["Article"]["slug"];
$newItem["Article"]["title"] = $item["Article"]["title"];
$newItem["Article"]["created"] = $item["Article"]["created"];
$newItem["User"] = $item["Article"]["User"];
$newItem["Album"]["Photo"] = $item["Article"]["Album"]["Photo"];
$item = $newItem;
$type = "article";
} elseif ($item["TagRelationship"]["video_id"] != null) {
$type = "video";
}
}
// If a list with videos is supplied, format the duration
if ($type == "video") {
// Set the coverImage
$coverImage = $this->CoverImage->getYouTubeCover($item["Video"]["youtubeId"]);
// If a video lasts shorter than an hour, only show minutes/seconds
if ($item[ucfirst($type)]["duration"] < 3600) {
$duration = gmdate("i:s", $item[ucfirst($type)]["duration"]);
}
// Otherwise show hours as well
else {
$duration = gmdate("H:i:s", $item[ucfirst($type)]["duration"]);
}
} elseif ($type == "article") {
$coverImage = $this->CoverImage->getArticleCover($item["Article"]["id"], $item["Album"]["Photo"]);
$coverImageOffset = $this->CoverImage->getArticleCoverOffset($item["Article"]["id"], $item["Album"]["Photo"]);
}
?>
<li>
<a href="/<?php print($type); ?>s/<?php print($item[ucfirst($type)]["id"]); ?>/<?php print($item[ucfirst($type)]["slug"]); ?>">
<p class="addedDate">Added:
<?php
print($this->Time->timeAgoInWords($item[ucfirst($type)]["created"], array(
'accuracy' => array('minute' => 'minute', 'hour' => 'hour', 'week' => 'week', 'day' => 'day', 'month' => 'month', 'year' => 'year'),
'end' => 'never')));
if ($type == "article") {
?>
by <?php print($item["User"]["username"]); ?>
<?php
}
?>
</p>
<ul class="itemDetails">
<li class="thumb" style="background-image: url(<?php print($coverImage); ?>); background-position: <?php print($coverImageOffset["x"]); ?>% <?php print($coverImageOffset["y"]); ?>%">
<?php
if ($mainType == "tag") {
?>
<p class="label"><?php print(ucfirst($type)); ?></p>
<?php
}
if ($type == "video") {
?>
<p class="duration"><?php print($duration); ?></p>
<?php
}
?>
</li>
<li>
<p><?php print($item[ucfirst($type)]["title"]); ?></p>
</li>
</ul>
</a>
</li>
<?php
}
?>
</ul>
<?php
$this->end();
?>
More than likely you are not unsetting the variables you set in the last element, they are remembered throughout the view. Try unsetting items after the first call -
$this->element('itemList', array('type' => "video", 'items' => $latestVideos));
echo $this->fetch('itemList');
unset($items);
Like the comment said though if this doesn't work we would need to see your element itself to diagnose the problem. If you go into your element itself at the end of everything being processed, unset the array housing all the items you are displaying. This should do the trick.
After some more research I came across the following in the CakePHP Cookbook:
// Clear the previous content from the sidebar block.
$this->assign('sidebar', '');
Sure enough this did the trick.
Thanks for your help though guys!
Im pretty new in WP so pls forgive me my ignorance im trying to learn.
So I have two Wp_Query (search by typeing in searchbar and search by taxonomy checkboxes) and I dont know how to mix them... If one works second dont and its a cricle.
<?php
global $search_ingr;
if(isset($search_ingr)) {
global $loop;
} else {
$query_params = getQueryParams();
if(isset($query_params['search'])) {
$query_params['post_title_like'] = $query_params['search'];
unset($query_params['search']);
}
$loop = new WP_Query(array(
'numberposts' => 60,
'posts_per_page' => 60,
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'products',
'post_status' => 'publish'
));
}
?>
<?php if(isset($search)): ?>
<div class="search-matches"><h4>Wyniki wyszukiwania:</h4><hr></div>
<?php endif; ?>
<?php if ($loop->have_posts()) :?>
<?php while($loop->have_posts()) : $loop->the_post (); ?>
<span class="tooltip tooltip-effect-4">
<span class="tooltip-item">
<div class="product">
<a href="<?php the_permalink(); ?>">
<div class="product-thumbnail"><span class="helper"></span><?php the_post_thumbnail(); ?></div>
<div class="product-name"><?php the_title(); ?></div>
</a>
</div>
</span>
<a href="<?php the_permalink(); ?>">
<span class="tooltip-content clearfix">
<?php the_post_thumbnail(); ?>
<span class="tooltip-text"><?php the_title(); ?></span>
</span>
</a>
</span>
<?php endwhile; ?>
<?php endif; ?>
Pretty long peace of code, Im pasting it with loop as well and above that I have search box and taxonomy list.
Additionally when I remove this:
// $loop = new WP_Query(array(
// 'numberposts' => 60,
// 'posts_per_page' => 60,
// 'orderby' => 'title',
// 'order' => 'ASC',
// 'post_type' => 'products',
// 'post_status' => 'publish'
// ));
Both searches works great(but I cant control post order and number of posts).
Any help on that?
The proper way to modify the wordpress loop would be like this.
Try this instead of the first block of PHP on top:
<?php
$search = get_query_var('s');
$loop = new WP_Query(array(
'numberposts' => 60,
'posts_per_page' => 60,
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'products',
'post_status' => 'publish',
's' => $search
));
?>
The potential problem is that you are using functions and parameters which aren't native to wordpress - getQueryParams() isn't a wordpress function and the WP_Query function doesn't accept a parameter with name 'post_title_like'. If this code works then you might be using some plugin for the search functionality in which case you would have to override the plugin behavior, not the default wordpress query.
Thanks a lot! Really appreciate youre help but it didnt resolve my problem.
I will try another way
This piece of code work perfectly for both searches but I need to change number of posts above limit of 10(thats why I started to messing with this code):
<?php
global $search_ingr;
if(isset($search_ingr)) {
global $loop;
} else {
$query_params = getQueryParams();
if(isset($query_params['search'])) {
$query_params['post_title_like'] = $query_params['search'];
unset($query_params['search']);
}
$loop = new WP_Query($query_params);
}
?>
And the getQueryParams() function:
function getQueryParams(){
global $query_string;
$parts = explode('&', $query_string);
$return = array();
foreach($parts as $part){
$tmp = explode('=', $part);
$return[$tmp[0]] = trim(urldecode($tmp[1]));
}
return $return;
}
Here is the dropdown in a form:
echo $this->Form->input('customer_id', array('id'=>'initials','label'=>'Customer', 'value'=>$customers));
The $customers is a key-value array like this:
array(
(int) 2 => 'Best customer',
(int) 5 => 'Good customer',
(int) 9 => 'Customer')
I need one value to be pre selected once the dropdown is created. I have tried to select a default value as the int id and as the customer name but none of them worked.
Here is the controller edit function:
function edit($id = null) {
$this->Project->id=$id;
$this->Project->recursive = 0;
$customers = $this->Customer->find('list', array('conditions'=>array('company_id'=>$this->Auth->user('company_id'))));
$this -> set('customers', $customers);
if(!$this->Project->exists()){
throw new NotFoundException('Invalid project');
}
if($this->request->is('post')|| $this->request->is('put')){
if($this->Project->save($this->request->data)){
$this->Session->setFlash('The project has been edited');
$this->redirect(array('controller'=>'projects', 'action'=>'view', $id));
} else{
$this->Session->setFlash('The project could not be edited. Please, try again');
}
}else{
$this->request->data = $this->Project->read();
$this->request->data['Project']['customer_id'] = 'New customer';
}
}
And here is the edit form:
<?php echo $this->Form->create('Project');?>
<fieldset>
<legend><?php __('Edit Project'); ?></legend>
<?php
echo $this->Form->input('customer_id', array('id'=>'initials','label'=>'Customer', 'value'=>$customers));
echo $this->Form->input('name');
echo $this->Form->input('project_nr', array('type'=>'text', 'label'=>'Case number'));
echo $this->Form->input('address');
echo $this->Form->input('post_nr');
echo $this->Form->input('city');
echo $this->Form->input('start_date', array('label'=>'Start Date', 'class'=>'datepicker', 'type'=>'text'));
echo $this->Form->input('finish_date', array('label'=>'End Date', 'class'=>'datepicker', 'type'=>'text'));
echo $this->Form->input('company_id', array('value' => $current_user['company_id'], 'type'=>'text', 'type'=>'hidden'));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
The best approach is to leverage the controller for this
if ($this->request->is('post')) {
$this->Model->create();
if ($this->Model->save($this->request->data)) {
...
} else {
...
}
} else {
/* Now here you can put your default values */
$this->request->data['Model']['field'] = ...;
}
For details see http://www.dereuromark.de/2010/06/23/working-with-forms/
This code is only updating one row (the one that matches the first in the array):
Edit: showing more code!
Here's my view. It's grabbing db entries based on an association (there's one model "clients" that has a one-to-many relationship with two other models, Programs and Users).
<div class="view">
<h2><?php echo h($program['Program']['title'])?></h1>
<?php echo $this->Form->create('User', array('action' => 'pushing')); ?>
<table id="pushTable">
<tr><th colspan="5">Select the athletes you would like to push this program to:</th></tr>
<tr>
<?php $i=0; ?>
<?php foreach ($clients['Players'] as $player) {?>
<?php if ($i == 0) {?><tr><?php } ?>
<td><?php echo $this->Form->checkbox($player['id']) . ' ' . $player['username'];?></td>
<?php if ($i == 4) {?></tr><?php $i = 0; } else { $i++; } ?>
<?php } ?>
</tr>
</table>
<?php echo $this->Form->end(__('Push')); ?>
</div>
In my Users controller:
public function pushing() {
if ($this->request->is('post') || $this->request->is('put')) {
$athletes = $this->request->data['User'];
foreach ( $athletes as $player => $flag){
if ($flag == 0){
unset($athletes[$player]);
}
}
$this->User->updateAll(
array('User.data' => "'foo'"),
array('User.id' => $athletes)
);
$this->Session->setFlash(__('Programs were pushed!'));
}
}
}
$athletes is the array is collected from checked boxes, and there seem to me no problems with that... so I'm not sure why the updateAll isn't iterating over each ID in the array...
Maybe it's not working for a db related reason? I'm developing on MAMP... maybe the db isn't set up for "atomic" stuff (only heard about that here today!).
I had previously tried using a foreach to loop over the id's, then in the foreach just did this (edit: more code!)
public function pushing() {
if ($this->request->is('post') || $this->request->is('put')) {
foreach ($this->request->data['User'] as $player => $flag) {
if ($flag) {
$this->User->id = $player; // set ID to player we want to save ($player is id that was suplpied in view to checkbox
$this->User->saveField('data', 'foo'); // then, push the data!
}
}
$this->Session->setFlash(__('Programs were pushed!'));
}
$this->autoRender = false;
$this->redirect(array('action' => 'index'));
}
But that caused weird results with redirection. No matter where I put redirection in that action, the save just wanted to do its own thing. That $this->autoRender did nothing. The controller still tried to resolve to the /pushing/ route
Give this a shot :)
In your view:
<div class="view">
<h2><?php echo h($program['Program']['title'])?></h1>
<?php echo $this->Form->create('User', array('action' => 'pushing')); ?>
<table id="pushTable">
<tr><th colspan="5">Select the athletes you would like to push this program to:</th></tr>
<tr>
<?php $i=0; ?>
<?php foreach ($clients['Players'] as $player) {?>
<?php if ($i == 0) {?><tr><?php } ?>
<td><?php echo $this->Form->input('Player.' . $player['id']. '.id', array('type' => 'checkbox', 'value' => $player['id'])) . ' ' . $player['username'];?></td>
<?php if ($i == 4) {?></tr><?php $i = 0; } else { $i++; } ?>
<?php } ?>
</tr>
</table>
<?php echo $this->Form->end(__('Push')); ?>
</div>
In your controller:
public function pushing() {
if ($this->request->is('post') || $this->request->is('put')) {
$athletes = $this->request->data['Player'];
$athlete_ids = array();
foreach($athletes as $a){
$athlete_ids[$a['id']] = $a['id'];
}
$this->User->updateAll(
array('User.data' => "'foo'"),
array('User.id' => $athlete_ids)
);
$this->Session->setFlash(__('Programs were pushed!'));
}
}
}
Hi had to change the code a bit to make it for work me..
$contactsids = array();
foreach($selected as $key => $val){
if(($val <> '') && ($val <> 0) ) {
$contactsids[$val] = $val;
}
}
$this->Contact->updateAll(
array('Contact.contact_category_id' => $category_id),
array('Contact.id' => $contactsids)
);