Beispiel #1
0
 public function render()
 {
     $view = new \Phalcon\Mvc\View\Simple();
     $template = $this->getTemplate();
     $view->setViewsDir(dirname($template) . '/');
     $filename = basename($template);
     $file = explode('.', $filename);
     array_pop($file);
     $file = implode('.', $file);
     return $view->render($file, $this->getParameters());
 }
$di->setShared('config', function () use($config) {
    return $config;
});
$di->setShared('session', function () use($config) {
    session_set_cookie_params($config->app->session_lifetime);
    if ($config->app->debug != 1) {
        ini_set('session.cookie_secure', '1');
        ini_set('session.cookie_httponly', '1');
    }
    $session = new Phalcon\Session\Adapter\Files();
    $session->start();
    return $session;
});
$di->setShared('view', function () use($config) {
    $view = new Phalcon\Mvc\View\Simple();
    $view->setViewsDir(ROOTDIR . '/app/views/');
    $view->registerEngines(array('.phtml' => function ($view) use($config) {
        $volt = new Phalcon\Mvc\View\Engine\Volt($view);
        $volt->setOptions(array('compiledPath' => ROOTDIR . '/tmp/volt/', 'compiledExtension' => '.php', 'compiledSeparator' => '_', 'compileAlways' => true));
        $compiler = $volt->getCompiler();
        $compiler->addFunction('recaptcha_get_html', function () use($config) {
            return "'" . recaptcha_get_html($config->captcha->pub, null, true) . "'";
        });
        return $volt;
    }));
    return $view;
});
$di->setShared('db', function () use($config) {
    $db = new \Phalcon\Db\Adapter\Pdo\Mysql($config->db->toArray());
    $db->execute('SET NAMES UTF8', array());
    return $db;
Beispiel #3
0
 /**
  * Catch the exception and log it, display pretty view
  *
  * @param \Exception $e
  */
 public static function exception(\Exception $e)
 {
     $config = \Phalcon\DI::getDefault()->getShared('config');
     $errors = array('error' => get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage(), 'info' => $e->getFile() . '[' . $e->getLine() . ']', 'debug' => "Trace: \n" . $e->getTraceAsString() . "\n");
     if ($config->app->env == "development") {
         // Display debug output
         $debug = new \Phalcon\Debug();
         $debug->onUncaughtException($e);
     } else {
         // Display pretty view of the error
         $di = new \Phalcon\DI\FactoryDefault();
         $view = new \Phalcon\Mvc\View\Simple();
         $view->setDI($di);
         $view->setViewsDir(APP_PATH . '/app/frontend/views/');
         $view->registerEngines(\Baseapp\Library\Tool::registerEngines($view, $di));
         echo $view->render('error', array('i18n' => I18n::instance(), 'config' => $config));
         // Log errors to file and send email with errors to admin
         \Baseapp\Bootstrap::log($errors);
     }
 }
    return $connection;
});
/**
 * @description Phalcon - \Phalcon\Mvc\Url
 */
$di->set(AppServices::URL, function () use($config) {
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri($config->application->baseUri);
    return $url;
});
/**
 * @description Phalcon - \Phalcon\Mvc\View\Simple
 */
$di->set(AppServices::VIEW, function () use($config) {
    $view = new Phalcon\Mvc\View\Simple();
    $view->setViewsDir($config->application->viewsDir);
    return $view;
});
/**
 * @description Phalcon - \Phalcon\Mvc\Router
 */
$di->set(AppServices::ROUTER, function () {
    return new \Phalcon\Mvc\Router();
});
/**
 * @description Phalcon - EventsManager
 */
$di->setShared(AppServices::EVENTS_MANAGER, function () use($di, $config) {
    return new \Phalcon\Events\Manager();
});
/**
Beispiel #5
0
<?php

$view = new \Phalcon\Mvc\View\Simple();
//A trailing directory separator is required
$view->setViewsDir("../app/views/");
// Render a view and return its contents as a string
echo $view->render("templates/welcomeMail");
// Render a view passing parameters
echo $view->render("templates/welcomeMail", array('email' => $email, 'content' => $content));
Beispiel #6
0
/**
 * Register the autoloader and tell it to register the tasks directory
 */
$loader = new \Phalcon\Loader();
$loader->registerNamespaces(["PhalconDocs" => __DIR__ . "/src/"]);
$loader->register();
$di = new \Phalcon\DI();
$view = new \Phalcon\Mvc\View\Simple();
$volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
$volt->setOptions(["compiledPath" => "scripts/compiled-views/", "compiledExtension" => ".compiled"]);
$compiler = $volt->getCompiler();
$compiler->addFunction("str_repeat", "str_repeat");
$view->registerEngines([".volt" => $volt]);
$view->setDI($di);
// A trailing directory separator is required
$view->setViewsDir("scripts/views/");
$api = new \PhalconDocs\ApiGenerator(CPHALCON_DIR);
$classDocs = $api->getClassDocs();
$docs = $api->getDocs();
$classes = [];
foreach (get_declared_classes() as $className) {
    if (!preg_match("#^Phalcon\\\\#", $className)) {
        continue;
    }
    $classes[] = $className;
}
foreach (get_declared_interfaces() as $interfaceName) {
    if (!preg_match("#^Phalcon\\\\#", $interfaceName)) {
        continue;
    }
    $classes[] = $interfaceName;
Beispiel #7
0
<?php

$di->set('view', function () {
    $view = new Phalcon\Mvc\View\Simple();
    $view->setViewsDir('../app/views/');
    return $view;
}, true);