Closed emiabr closed 10 years ago
I've had problems doing it that way. Per the wiki Getting Started just add the following line to your routes and remove the setExtensions part:
Router::parseExtensions('json');
If this does not work then please reply with your CakePHP version and anything out of the ordinary with your setup that I should be aware of. Thanks for using!
Thanks for your assistance! Got me a little way, but now when I go to "Drawings/index.json" I dont get a correct json data. index.ctp
<?php echo $this->Html->css('smoothness/jquery-ui-1.10.4.custom.min'); ?>
<?php echo $this->Html->css('demo_table.css'); ?>
<?php echo $this->Html->script('jquery-1.11.0.min'); ?>
<?php echo $this->Html->script('jquery-ui-1.10.4.custom.min'); ?>
<?php echo $this->Html->script('jquery.dataTables.min'); ?>
<script>
$(function() {
$('#drawings-table').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "<?php echo $this->Html->url(array('controller' => 'drawings', 'action' => 'index.json')); ?>",
"aoColumns": [
{mData:"Drawing.id"},
{mData:"Drawing.ritning"},
{mData:"Drawing.rev"},
{mData:"Drawing.rev_kom"},
{mData:"Drawing.ben"},
{mData:"Drawing.artiklar"},
{mData:"Drawing.typ"},
{mData:"Drawing.ben_1"},
{mData:"Drawing.ben_2"},
{mData:"Drawing.ben_3"},
{mData:"Drawing.ben_4"},
{mData:"Drawing.status"},
{mData:"Drawing.skapad_av"},
{mData:"Drawing.skapad_nar"},
{mData:"Drawing.andrad_av"},
{mData:"Drawing.andrad_nar"},
{mData:"Drawing.ben_eng"},
{mData:"Drawing.ben_eng_1"},
{mData:"Drawing.ben_eng_2"},
{mData:"Drawing.ben_eng_3"},
{mData:"Drawing.ben_eng_4"},
{mData:"Drawing.kg_kod"},
{mData:"Drawing.variabler"},
{mData:"Drawing.tvt_text"},
{mData:"Drawing.taggar"}
],
});
});
</script>
DrawingsController.php
App::uses('AppController', 'Controller');
/**
* Drawings Controller
*
* @property Drawing $Drawing
* @property PaginatorComponent $Paginator
* @property DataTableComponent $DataTable
*/
class DrawingsController extends AppController {
/**
* Components
*
* @var array
*/
public $components = array('Paginator', 'DataTable');
/**
* index method
*
* @return void
*/
public function index() {
$this->paginate = array(
'fields' => array(
'Drawing.id',
'Drawing.ritning',
'Drawing.rev',
'Drawing.rev_kom',
'Drawing.ben',
'Drawing.artiklar',
'Drawing.typ',
'Drawing.ben_1',
'Drawing.ben_2',
'Drawing.ben_3',
'Drawing.ben_4',
'Drawing.status',
'Drawing.skapad_av',
'Drawing.skapad_nar',
'Drawing.andrad_av',
'Drawing.andrad_nar',
'Drawing.ben_eng',
'Drawing.ben_eng_1',
'Drawing.ben_eng_2',
'Drawing.ben_eng_3',
'Drawing.ben_eng_4',
'Drawing.kg_kod',
'Drawing.variabler',
'Drawing.tvt_text',
'Drawing.taggar'
)
);
$this->DataTable->mDataProp = true;
$this->set('response', $this->DataTable->getResponse());
$this->set('_serialize','response');
}
Hope you can help me! I'm using CakePhp 2.4.7,
In app/Config/routes.php try:
Router::setExtensions(array('json'),true);
Router::parseExtensions();
When you say you don't get "correct json data" what does that mean?
Also have you tried setting up and running the demo application on your system?
Hi, Probably a simple error from my part, but I'm getting an error when trying to run my site. Any idea what I'm doing wrong? routes.php contains:: CakePlugin::routes(); Router::setExtensions(array('json'),true); Router::parseExtensions('json');
Thanks in advance!