Re: jQuery sortable: how to update database?

2014-02-02 Thread Sam Clauw
Indeed Euromark, that was the reason it didn't work. I changed the notation 
too so I have an up-to-date program running;)
Salines & Euromark: thank you for helping me with this issue, I 
*realy*appreciate this! I can go further exploring CakePHP now! :)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: jQuery sortable: how to update database?

2014-02-02 Thread euromark
you forgot the () after the method names

  $this->RequestHandler->isAjax() 

etc

also, this is deprecated, use

  $this->request->is('ajax') 

etc as documeted


Am Sonntag, 2. Februar 2014 12:16:02 UTC+1 schrieb Sam Clauw:
>
> Allright, that will be much easier to understand the whole AJAX and 
> request happening! Last years, I've realy struggled with this and I think 
> it will be a lot clearer for me now. Thank you!
> To go back on my sorting problem: it isn't working yet. I dugged into 
> CakePHP's Request Handling documentation and tried to catch the POST values 
> from that AJAX request. The strange thing is that my controller seems to 
> haven't catched a request at all! Here's my controller code:
>
> class AttractionsController extends CoasterCmsAppController
> {
> public $components = array(
> 'RequestHandler'
> );
> ...
> public function beforeFilter() {
> if ($this->RequestHandler->isAjax) {
> echo 'Ajax';
> } elseif ($this->RequestHandler->isPost) {
> echo 'Post';
> } elseif  ($this->RequestHandler->isGet) {
> echo 'Get';
> } else {
> echo 'Damn, this string shouldn't be here!';
> }
> }
> }
>
> As you can guess, I always got the string "Damn, this string shouldn't be 
> here!" outputted (instead of the "Ajax" echo). However, my javascript has 
> no errors and I do get my data when I alert it in the "succeed" of my 
> $.ajax. Is there something crucial that I'm forgetting? :)
>
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: jQuery sortable: how to update database?

2014-02-02 Thread Sam Clauw
Allright, that will be much easier to understand the whole AJAX and request 
happening! Last years, I've realy struggled with this and I think it will 
be a lot clearer for me now. Thank you!
To go back on my sorting problem: it isn't working yet. I dugged into 
CakePHP's Request Handling documentation and tried to catch the POST values 
from that AJAX request. The strange thing is that my controller seems to 
haven't catched a request at all! Here's my controller code:

class AttractionsController extends CoasterCmsAppController
{
public $components = array(
'RequestHandler'
);
...
public function beforeFilter() {
if ($this->RequestHandler->isAjax) {
echo 'Ajax';
} elseif ($this->RequestHandler->isPost) {
echo 'Post';
} elseif  ($this->RequestHandler->isGet) {
echo 'Get';
} else {
echo 'Damn, this string shouldn't be here!';
}
}
}

As you can guess, I always got the string "Damn, this string shouldn't be 
here!" outputted (instead of the "Ajax" echo). However, my javascript has 
no errors and I do get my data when I alert it in the "succeed" of my 
$.ajax. Is there something crucial that I'm forgetting? :)


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: jQuery sortable: how to update database?

2014-02-02 Thread Salines
*One additional thing: where in Chrome developer tools can you see those 
ajax values? Elements, Network, Sources, ...? ;)*

Open CDT and select the Network tab, then sort the table and view the query 
output in the Network tab. Select an output request for more details ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: jQuery sortable: how to update database?

2014-02-01 Thread Sam Clauw
Ow yes, you've got me on the right way! I've changed my .ctp file now:


$(function() {
$('.sortable tbody').sortable({
axis: 'y',
scroll: true,
opacity: 0.5,
revert: 100,
cursor: 's-resize',
items: 'tr.grab',

// volledige breedte van  behouden

helper: function (e, ui) {
ui.children().each(function () {
$(this).width($(this).width());
});
return ui;
},
stop: function (event, ui) {
var data = $(this).sortable('serialize');

// POST naar server ($.post of $.ajax)

$.ajax({
data: data,
type: 'POST',
url: '*here; ?>*'
});
}
}).disableSelection();
});


Then, I'll check on a submitted POST in my sort action and will handle the 
update.

One additional thing: where in Chrome developer tools can you see those 
ajax values? Elements, Network, Sources, ...? ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: jQuery sortable: how to update database?

2014-02-01 Thread Salines
You do it in the wrong way. 

In your controller create method and then put the code that will save your 
changes.

use chrome developer tools or firefox firebug to see which values ​​are 
sent via ajax query

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


jQuery sortable: how to update database?

2014-02-01 Thread Sam Clauw
Hi there!

I've made a sortable table in my custom CMS system. You can drag and drop 
's so they have another position. 

This is the javascript in my sort.ctp file:


$(function() {
$('.sortable tbody').sortable({
axis: 'y',
scroll: true,
opacity: 0.5,
revert: 100,
cursor: 's-resize',
items: 'tr.grab',

// volledige breedte van  behouden

helper: function (e, ui) {
ui.children().each(function () {
$(this).width($(this).width());
});
return ui;
},
stop: function (event, ui) {
var data = $(this).sortable('serialize');

// POST naar server ($.post of $.ajax)

$.ajax({
data: data,
type: 'POST',
url: ''
});
}
}).disableSelection();
});


Then, I've made a "sort.php" file and I've put it in the lib folder of my 
plugin (CoasterCms/Lib/sort.php). Here's the place where the magic should 
happen...
But it doesn't happen at all. The file currently looks like this:

getDataSource();

$db->updateAll(
array( // fields
'Attraction.show' => 'N'
),
array( // conditions
'Attraction.id' => 3
)
);

?>

Unfortunately, it does nothing. The baddest thing is that I can't test it 
on errors because I cannot reach the lib file by an url. Is there anybody 
who can guide me on the right way? How can I connect to my database and do 
some update actions on a specific model?

Thanks for helping me ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.