Пример #1
0
<?php

$app->put('/', function ($req, $res, $args) {
    // var_dump($req->getParsedBody());exit;
    // $this->get('logger')->info(json_encode($req->getParsedBody()));
    if ($req->getParsedBody()) {
        $data = $req->getParsedBody();
        $data['password'] = base64_encode(hash_hmac("sha256", isset($data['password']) ? $data['password'] : $this->get('initPWD'), $this->get('secret'), true));
        // $data = $db->insert('user', $data);
        $model = new userModel();
        $result = $model->add($data);
        // echo $db->last_query();
        return $res->write(json_encode($result));
    } else {
        return $res->withStatus(403)->write("No Post data!");
    }
});
$app->get('/{id:[0-9]+}', function ($req, $res, $args) {
    // $db = $this->get('db');
    // $data = isset($args['id']) ? $db->select('user', '*', ['id' => $args['id']]) : $db->select('user', '*', ['LIMIT' => 1]);
    // $data = $db->select('user', '*', ['id' => $args['id']]);
    $model = new userModel();
    $result = $model->get($args['id']);
    // echo $db->last_query();
    return $res->write(json_encode($result));
});
$app->post('/{id:[0-9]+}', function ($req, $res, $args) {
    if ($req->getParsedBody()) {
        $data = $req->getParsedBody();
        $model = new userModel();
        // $data = isset($args['id']) ? $db->select('user', '*', ['id' => $args['id']]) : $db->select('user', '*', ['LIMIT' => 1]);
Пример #2
0
 function createUser($name, $password)
 {
     $data['lastlogin'] = date("Y-m-d h:i:s");
     $data['username'] = $name;
     $data['password'] = MD5($password);
     $userDao = new userModel();
     $userDao->add($data);
     return $userDao->where($data)->find();
 }