Пример #1
0
 public static function render($path, $data)
 {
     self::$data = $data;
     if (!is_file($path)) {
         App::Abort();
     }
     include $path;
 }
Пример #2
0
 public function make($filename, $data = [])
 {
     $view = new View($this);
     $view->setPath($this->app->basePath($this->app->config->get('app.view.templates', 'app' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR)));
     $view->setCachePath($this->app->cachePath($this->app->config->get('app.view.cache', 'views' . DIRECTORY_SEPARATOR)));
     $view->setFilename($filename);
     $view->data($data);
     return $view;
 }
Пример #3
0
 /**
  * Add $key => $value to global data
  *
  * @param array $data data to add.
  */
 public static function add_data($data = null)
 {
     if (is_null($data)) {
         return false;
     }
     if (is_array($data)) {
         self::$data = array_merge(self::$data, $data);
     }
     return count(self::$data);
 }
Пример #4
0
 /**
  * Loads a page object into the current view, if the page exists. Otherwise 404 error is returned.
  *
  * Route: page/:slug
  *
  * @param string $slug The slug of the page to get.
  */
 public static function view($slug)
 {
     $page = Page::page()->find($slug);
     if ($page) {
         View::setTitle($page->title);
         View::data('page', $page);
         return;
     }
     return ERROR_404;
 }
Пример #5
0
 function testView()
 {
     $view = new View();
     $view->no_layout = true;
     $view->load("test_view");
     $view->data("test", "World");
     ob_start();
     $view->dump(array("controller" => "testz", "action" => "test"));
     $output = ob_get_contents();
     ob_end_clean();
     $this->assertEqual($output, "Hello World");
 }
Пример #6
0
        } elseif (!String::startsWith($currentRoute, 'admin/login')) {
            $noAccess = !User::current()->hasPermission('admin.access');
            $isAnon = User::current()->isAnonymous();
            if (!$isAnon && $noAccess) {
                Message::error('You do not have admin access permissions.');
                unset($_SESSION[Config::get('user.session_key')]);
            }
            if ($isAnon || $noAccess) {
                Url::redirect('admin/login');
            }
        }
        Admin::setInAdmin(true);
        View::setPath(ROOT . 'core/admin/');
    }
}, 'module.response' => function ($response = null) {
    if (Admin::inAdmin()) {
        View::data('adminContent', $response);
    }
}, 'view.load' => function ($module, $controller, $method) {
    if (Admin::inAdmin()) {
        $paths = array(sprintf('%s/%s', $controller, $method), sprintf('%s_%s', $controller, $method));
        foreach ($paths as $path) {
            $viewFile = Load::getModulePath($module) . Config::get('view.dir') . $path . EXT;
            Log::debug('admin', 'Checking for custom view: ' . $viewFile);
            if (file_exists($viewFile)) {
                Log::debug('admin', 'Loading custom view: ' . $viewFile);
                return $viewFile;
            }
        }
    }
}));
Пример #7
0
 /**
  * this is the main feature of the view, in the MVC paradigm the controller sends updates to the view, this is 
  * the method which captures the updates.  
  * 
  * As this view is part of the test framework, all we do here is capture the values
  *
  * @param string $uri 
  * @param array $vars 
  * @param string $message 
  * @return void
  * @author Craig Ulliott
  */
 public static function update($uri, $data = null, $message = null)
 {
     self::$uri = $uri;
     self::$data = $data;
     self::$message = $message;
 }