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