データベースからフッタブルに動的データを追加したい。しかし、ajaxのURLでコントローラーを指定しているときに404エラーが発生します。
これは私のすべての投稿ビューです:
<?php
use yii\helpers\Html;
use yii\grid\GridView;
$this->title = 'Posts';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="bg-light lter b-b wrapper-md">
<div class="row">
<div class="col-sm-6">
<h1 class="m-n font-thin h3"><?= Html::encode($this->title) ?></h1>
</div>
<div class="col-sm-5">
<?= Html::a('Create Post', ['create'], ['class' => 'btn btn-success pull-right']) ?>
</div>
</div>
</div>
<div class="panel-body">
<div class="tab-pane active" id="demo">
<div class="row">
<div class="">
<label class="col-sm-1 control-label">Search:</label>
<div class="col-sm-3">
<input class="form-control" id="filter" type="text"/>
</div>
<div class="col-sm-3">
<a href="#clear" class="clear-filter" title="clear filter">[clear]</a>
<span class="row-count"></span>
</div>
</div>
</div>
<table class="table demo" data-filter="#filter" data-page-size="5">
<thead>
<tr>
<th data-toggle="true">
Title
</th>
<th data-hide="phone">
Description
</th>
<th data-hide="phone,tablet">
Created Date and Time
</th>
<th>
Status
</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot class="hide-if-no-paging">
<tr>
<td colspan="5">
<div class="pagination pagination-centered"></div>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
function create_row (item) {
var row = $('<tr><td>' + item.title + '</td><td>' + item.date + '</td></tr>');
return row;
}
$.ajax({
url : '<?php echo BASEURL.'post/getFooTableData'?>', **Here i am getting 404 error**
data: { },
success : function(data) {
$.each(data, function(index, item){
var row = create_row(item);
$('table tbody').append(row);
});
$('table').trigger('footable_initialize');
},
error : function(xhr, statusText, error) {
alert("Error! Could not retrieve the data.");
}
});
$('table').footable({
bookmarkable: { enabled: true }
}).bind({
'footable_filtering': function (e) {
var selected = $('.filter-status').find(':selected').text();
if (selected && selected.length > 0) {
e.filter += (e.filter && e.filter.length > 0) ? ' ' + selected : selected;
e.clear = !e.filter;
}
},
'footable_filtered': function() {
var count = $('table.demo tbody tr:not(.footable-filtered)').length;
$('.row-count').html(count + ' rows found');
}
});
$('.clear-filter').click(function (e) {
e.preventDefault();
$('.filter-status').val('');
$('table.demo').trigger('footable_clear_filter');
$('.row-count').html('');
});
$('.filter-status').change(function (e) {
e.preventDefault();
$('table.demo').data('footable-filter').filter( $('#filter').val() );
});
});
</script>
これは私のポストコントローラー関数です:
<?php
public function getFooTableData()
{
$fooTableData = new Post();
$fooTable = $fooTableData->getFooTableData();
// print_r($fooTable);
// exit;
return $fooTable;
}
?>
これはポストモデルです:
<?php
public function getFooTableData()
{
$query = new Query;
$query->select('*')
->from('post');
$command = $query->createCommand();
$posts = $command->queryAll();
return json_encode($posts)
}
?>
私のインデックスメソッドが呼び出されると、404 Not Foundエラーが発生します
データ変数でデータを取得するにはどうすればよいですか?