public function __construct(App $app) { $this->app = $app; $this->view = new View(); $file = __DIR__ . '/../view/' . $app->getController() . '/' . $app->getAction() . '.phtml'; $this->view->setFile($file); }
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'); }
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)); }
<?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); });
<?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();
public static function endForm() { return App::getComponent('view')->render(__DIR__ . '/views/endForm.php'); }
public function action404() { $params['home_url'] = App::getComponent('request')->getBaseUrl(); return $this->renderPartial('404', $params); }
public function actionLogout() { App::getComponent('user')->logout(); $this->redirect('user', 'login'); }
public function login() { if ($this->validate()) { return App::getComponent('user')->login($this->getUser()); } }
/** * 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; }
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; }