Updated mithril to do as it has to do
This commit is contained in:
parent
7c61498047
commit
b704e2f1a7
@ -1,31 +1,34 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
use Core\Token;
|
||||
|
||||
use App\Models\Post;
|
||||
|
||||
class Api
|
||||
{
|
||||
public function posts() {
|
||||
$get = [
|
||||
'data' => [
|
||||
[
|
||||
'id' => 1,
|
||||
'judul' => 'post_1',
|
||||
'status' => 1
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'judul' => 'post_2',
|
||||
'status' => 0
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'judul' => 'post_3',
|
||||
'status' => 2
|
||||
]
|
||||
]
|
||||
];
|
||||
private $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->model = new Post();
|
||||
}
|
||||
|
||||
public function posts() {
|
||||
$get = [];
|
||||
$get['count'] = 0;
|
||||
$get['data'] = $this->model->showJoin([
|
||||
['pengumuman.status', '=', 1]
|
||||
]);
|
||||
|
||||
if (array_key_exists(0, $get['data']) == false) {
|
||||
$temp_data = $get['data'];
|
||||
unset($get['data']);
|
||||
$get['data'][] = $temp_data;
|
||||
$temp_data = [];
|
||||
}
|
||||
|
||||
if ($get['data'] != false) {
|
||||
$get['count'] = count($get['data']);
|
||||
}
|
||||
|
||||
$get['count'] = count($get['data']);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($get);
|
||||
}
|
||||
|
@ -7,13 +7,14 @@
|
||||
</main>
|
||||
<script>
|
||||
var root = document.getElementById('mit')
|
||||
var text = ''
|
||||
var count = 0
|
||||
var timer = 10000; // 10 seconds
|
||||
|
||||
var rend = {
|
||||
view: function() {
|
||||
return m('section', [
|
||||
m('h1', 'Mithril'),
|
||||
m('p', text),
|
||||
m('p', 'You got ' + count + ' data(s)'),
|
||||
m('button', {
|
||||
class: 'pseudo',
|
||||
onclick: getdata
|
||||
@ -30,14 +31,13 @@
|
||||
withCredentials: true
|
||||
})
|
||||
.then(function(get) {
|
||||
getdata.list = get.data
|
||||
getdata.list = get
|
||||
count = getdata.list.count
|
||||
})
|
||||
|
||||
for (var i = 0; i < getdata.list.length; i++) {
|
||||
text = text + getdata.list[i].judul + ' '
|
||||
}
|
||||
}
|
||||
|
||||
m.mount(root, rend)
|
||||
|
||||
setInterval(getdata, timer);
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user