Exemple #1
0
 public static function resolve($url)
 {
     if (strstr($url, '/admin') !== false) {
         Router::$module = 'admin';
     } else {
         Router::$module = 'site';
     }
     foreach (self::$routes[self::$module] as $route) {
         $regex = $route['regex'];
         if (isset($route['params'])) {
             foreach ($route['params'] as $k => $v) {
                 $regex = str_replace('{' . $k . '}', "({$v})", $regex);
             }
         }
         $regex = "#^{$regex}\$#";
         if (preg_match($regex, $url, $matches)) {
             $params = array();
             array_shift($matches);
             self::$_controller = Router::$module . '\\' . $route['controller'];
             self::$_action = $route['action'];
             if ($matches) {
                 $params = array_combine(array_keys($route['params']), $matches);
             }
             $_GET = $_GET + $params;
         }
     }
     if (!self::$_controller || !self::$_action) {
         throw new Exception('Page not found', 404);
     }
 }
Exemple #2
0
 /**
  * Adds a new user row.
  * 
  * @return array $result
  */
 public function add($data)
 {
     $result = array('data' => $data, 'select' => array($this->lang->mysql->disable, $this->lang->mysql->enable), 'nav_mysql' => true);
     $vars = new Vars();
     if ($vars->isPost()) {
         $form = new FormValidate($data);
         $validate = $form->checkFields($this->validate);
         if (isset($validate['failed'])) {
             $result['validate'] = $validate;
         } else {
             $query = "INSERT INTO user SET username=?, email=?, active=?";
             $params = array($vars->post('username'), $vars->post('email'), $vars->post('status'));
             $data = $this->db->run($query, $params);
             $router = new Router();
             $router->redirect('mysql');
         }
     }
     return $result;
 }
 public function editSourceAction()
 {
     $title = MetaHelper::setPageTitle('Редактировать источник');
     $model = new WeatherModel();
     $request = new Request();
     $data = $model->getSource($request->get('id'));
     if ($request->post('editSource')) {
         $action = $model->updateSource($request->get('id'), $request->post('source_name'), $request->post('source_weather_file'), $request->post('source_cities_file'), $request->post('source_default_value'));
         if ($action == true) {
             header("Location:  " . Router::getRoute('admin', 'success'));
         } else {
             header("Location:  " . Router::getRoute('admin', 'fail'));
         }
     }
     $args = ['page_title' => $title, 'data' => $data, 'msg' => isset($msg) ? $msg : null];
     return $this->render('editSource.phtml', $args, 'admin');
 }
<?php

use Controller\BlogController;
use Model\BlogManager;
use Lib\SplClassLoader;
use Lib\Router;
session_start();
require __DIR__ . '/Lib/SplClassLoader.php';
$controllerLoader = new SplClassLoader('Controller', '');
$controllerLoader->register();
$libLoader = new SplClassLoader('Lib', '');
$libLoader->register();
$modelLoader = new SplClassLoader('Model', '');
$modelLoader->register();
$viewLoader = new SplClassLoader('View', '');
$viewLoader->register();
$manager = new BlogManager();
$controller = new BlogController($manager);
if (isset($_POST['comment'])) {
    $manager->processCommentForm();
}
$uri = $_SERVER['REQUEST_URI'];
$router = new Router($controller, $manager, $uri);
$content = $router->route();
include './View/layout.php';
Exemple #5
0
<?php

use lib\Router;
require "bootstrap.php";
require "routes.php";
echo Router::dispatch();
Exemple #6
0
$url = $url[0];
//функуия автозагрузки
function __autoload($classname)
{
    $classFile = str_replace('\\', '/', $classname);
    if (file_exists(ROOT . $classFile . '.php')) {
        require ROOT . $classFile . '.php';
    } else {
        throw new Exception("{$classFile} not found");
    }
}
try {
    $dbh = new PDO($dsn, $user, $password);
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    Registry::set('dbh', $dbh);
    Router::resolve($url);
    $_controller = Router::$_controller;
    $_action = Router::$_action;
    $_controller = '\\Controller\\' . ucfirst($_controller) . "Controller";
    $_action .= "Action";
    $_controller = new $_controller();
    if (method_exists($_controller, $_action)) {
        $content = $_controller->{$_action}();
    } else {
        throw new Exception("{$_action} not found");
    }
} catch (PDOException $e) {
    $to = $for_pdo_exception['email'];
    $subject = $for_pdo_exception['subject'];
    $message = $e->getMessage();
    mail($to, $subject, $message);
Exemple #7
0
Router::get('/odpovedat/:id', 'BaseController');
// redirect all angular's partials to the framework's views
Router::get('/partials/home', 'BaseController@home');
Router::get('/partials/users', 'UserController@users');
Router::get('/partials/user/:id', 'UserController@profile');
Router::get('/partials/posts/:id', 'PostController@posts');
Router::get('/partials/post/:id', 'PostController@post');
Router::get('/partials/followers-posts', 'PostController@fromFollowers');
Router::get('/partials/followers/:id', 'UserController@followers');
Router::get('/partials/following/:id', 'UserController@following');
Router::get('/partials/friends/:id', 'UserController@following');
Router::get('/partials/amessage/:id', 'MessageController@message');
Router::get('/partials/new-message/:id', 'MessageController@newMessage');
Router::get('/partials/reply/:id', 'MessageController@reply');
Router::get('/partials/:partial', 'BaseController@partials');
// api
Router::post('/login', 'UserController@login');
Router::post('/logout', 'UserController@logout');
Router::post('/register', 'UserController@register');
Router::post('/change-password', 'UserController@changePassword');
Router::post('/change-profile', 'UserController@changeProfile');
Router::post('/upload', 'UserController@upload');
Router::post('/follow/:id', 'UserController@follow');
Router::post('/notifications', 'NotificationController@get');
Router::post('/update-notifications', 'NotificationController@update');
Router::post('/post', 'PostController@create');
Router::post('/new-message', 'MessageController@create');
Router::post('/reply', 'MessageController@update');
// test
Router::get('/test', 'BaseController@test');
 public function admLogoutAction()
 {
     Session::delete('user');
     Session::setFlash('You have logged out!');
     header("Location:  " . Router::getRoute('admin', 'adm_default'));
 }