Beispiel #1
0
 public function __construct(App $app)
 {
     $this->app = $app;
     $this->view = new View();
     $file = __DIR__ . '/../view/' . $app->getController() . '/' . $app->getAction() . '.phtml';
     $this->view->setFile($file);
 }
Beispiel #2
0
 public function actionDelete($id)
 {
     $contact = (new Contact())->findById((int) $id)[0];
     $deleted = false;
     if ($contact->user_id == App::getComponent('user')->getId()) {
         $deleted = (bool) $contact->delete();
     }
     if (App::getComponent('request')->isAjax()) {
         return $deleted;
     }
     $this->redirect('contacts');
 }
Beispiel #3
0
 function main()
 {
     //parent::main();
     /* Exemplo de uso do método push/pull da classe App
      */
     App::push('list', function ($txt) {
         return ' -- ' . $txt . ' -- ';
     });
     $h = App::pull('list');
     echo $h('olá');
     App::push('can', new \Lib\Can(null, true));
     echo '<br>Código CAN para o número "108788293834878" : ' . App::pull('can')->encode(108788293834878);
     $t = intval(microtime(true));
     echo '<br>Código CAN para o time "' . $t . '" : ' . ($d = App::pull('can')->encode($t));
     echo '<br>Decodificando: ' . App::pull('can')->decode($d);
     //mostrando a chve CAN
     p(file_get_contents(CONFIG_PATH . 'keys/can.key'), true);
     //Teste de saída do método MAIN
     exit('<br> -- Controller\\Home\\main : ' . p($this->params, true));
 }
Beispiel #4
0
<?php

use Model\Users;
$app->post('/users', function () use($app) {
    $data = json_decode(file_get_contents("php://input"));
    $user = new Users();
    $user->uuid = \Lib\App::v4();
    $user->name = $data->name;
    $user->email = $data->email;
    $user->password = password_hash($data->password, PASSWORD_BCRYPT);
    $user->save();
    echo json_encode($data);
});
$app->post('/users/login', function () use($app) {
    $data = json_decode(file_get_contents("php://input"));
    $user = new Users();
    $result = $user->where('email', $data->email)->first();
    echo json_encode($result);
});
$app->post('/users/is_email_unique', function () use($app) {
    $data = json_decode(file_get_contents("php://input"));
    $user = new Users();
    $isExist = $user->whereEmail($data->email)->first();
    echo json_encode($isExist);
});
Beispiel #5
0
<?php

/**
 * Created by PhpStorm.
 * User: nmakarenko
 * Date: 30.06.15
 * Time: 16:38
 */
function __autoload($class)
{
    require str_replace('\\', '/', $class) . '.php';
}
use lib\App;
$app = new App();
$app->run();
Beispiel #6
0
 public static function endForm()
 {
     return App::getComponent('view')->render(__DIR__ . '/views/endForm.php');
 }
Beispiel #7
0
 public function action404()
 {
     $params['home_url'] = App::getComponent('request')->getBaseUrl();
     return $this->renderPartial('404', $params);
 }
Beispiel #8
0
 public function actionLogout()
 {
     App::getComponent('user')->logout();
     $this->redirect('user', 'login');
 }
Beispiel #9
0
 public function login()
 {
     if ($this->validate()) {
         return App::getComponent('user')->login($this->getUser());
     }
 }
Beispiel #10
0
 /**
  *  Deleta gravações anteriores a 30 dias
  *
  */
 function clear()
 {
     App::db()->query('DELETE FROM access WHERE DATE(access.IDATE) <= DATE(DATE(NOW())-30)');
     return $this;
 }
Beispiel #11
0
 public function getUrl($params = [], $escaped = true)
 {
     $search = [];
     if (!empty($_REQUEST[$this->search])) {
         $search[$this->search] = array_filter($_REQUEST[$this->search], function ($value) {
             return !empty($value);
         });
     }
     $query = array_merge($_GET, $search, $params);
     if (isset($query[$this->page]) && $query[$this->page] > $this->getAvailablePages()) {
         $query[$this->page] = $this->getAvailablePages();
     }
     if (isset($query[$this->page]) && $query[$this->page] < 1) {
         $query[$this->page] = 1;
     }
     $query = http_build_query($query);
     if ($escaped) {
         $query = htmlspecialchars($query);
     }
     return App::getComponent('request')->getBaseUrl() . '?' . $query;
 }