コード例 #1
0
ファイル: MailMessage.php プロジェクト: keepeye/EvaEngine
 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());
 }
コード例 #2
0
ファイル: FactoryDefault.php プロジェクト: skullab/area51
 public function initializeServices()
 {
     $this->set(ServiceManager::CONFIG, function () {
         $files = array('dirs' => CORE_PATH . 'config/dirs.ini.php', 'db' => CORE_PATH . 'config/db.ini.php', 'smtp' => CORE_PATH . 'config/smtp.ini.php');
         $app = new ConfigIni(CORE_PATH . 'config/app.ini.php');
         foreach ($files as $file) {
             if (file_exists($file)) {
                 $c = new ConfigIni($file);
                 $app->merge($c);
             }
         }
         $this->set(ServiceManager::VIEW_JS, function () {
             $simple = new \Phalcon\Mvc\View\Simple();
             $simple->registerEngines(array(".js" => "Thunderhawk\\API\\Mvc\\View\\Engine\\VoltJs"));
             return $simple;
         }, true);
         //$dirs = new ConfigIni ( $files['dirs'] );
         //$db = new ConfigIni ( CORE_PATH . 'config/db.ini.php' );
         //$smtp = new ConfigIni ( CORE_PATH . 'config/smtp.ini.php' );
         if (file_exists(CORE_PATH . 'config/modules.ser')) {
             $modulesInstalled = unserialize(file_get_contents(CORE_PATH . 'config/modules.ser'));
         } else {
             require CORE_PATH . 'config/modules.php';
         }
         $modules = new ConfigArray($modulesInstalled);
         //file_put_contents(CORE_PATH.'config/modules.ser', serialize($modulesInstalled));
         //$app->merge ( $dirs );
         //$app->merge ( $db );
         $app->merge($modules);
         //$app->merge ( $smtp );
         return $app;
     }, true);
     //require CORE_PATH . 'core/config/services.php';
     require CORE_PATH . 'config/services.php';
     foreach ($services as $service => $function) {
         $this->set($service, $function, true);
     }
 }
コード例 #3
0
$di = new \Phalcon\DI\FactoryDefault();
$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());
コード例 #4
0
ファイル: Bootstrap.php プロジェクト: al35mm/Phalcon-Rocket
 /**
  * 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);
     }
 }
コード例 #5
0
<?php

$view = new Phalcon\Mvc\View\Simple();
echo $view->render('templates/my-view', array('content' => $html));
コード例 #6
0
    $connection->setEventsManager($di->get(AppServices::EVENTS_MANAGER));
    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();
});
コード例 #7
0
ファイル: CLI.php プロジェクト: inno-v/LinInLiao
$di->set('config', $config, true);
/**
 * Database connection is created based in the parameters defined in the configuration file
 */
$di->set('db', function () use($config) {
    $db_config = $config->database[ENVIRONMENT];
    return new \Phalcon\Db\Adapter\Pdo\Mysql(array('host' => $db_config->dbhost, 'username' => $db_config->dbusername, 'password' => $db_config->dbpassword, 'dbname' => $db_config->dbname));
}, true);
$di->set('acl', function () use($di, $config) {
    return new Phalcon\Acl\Adapter\Database(array('db' => $di->get('db'), 'roles' => 'roles', 'rolesInherits' => 'roles_inherits', 'resources' => 'resources', 'resourcesAccesses' => 'resources_accesses', 'accessList' => 'access_list'));
}, true);
$di->set('translate', function () {
    return new Lininliao\Library\Locale\Translate(SITENAME);
}, true);
$di->set('simpleView', function () use($di, $config) {
    $view = new \Phalcon\Mvc\View\Simple();
    $view->setDI($di);
    $view->registerEngines(array('.volt' => function ($view, $di) {
        $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
        $compiledPath = ROOT . DS . 'cache' . DS . SITENAME . DS . 'volt' . DS;
        if (!file_exists($compiledPath)) {
            mkdir($compiledPath, 0777, true);
        }
        $volt->setOptions(array('compiledPath' => $compiledPath, 'compiledExtension' => '.cache', 'compiledSeparator' => '%', 'stat' => true, 'compileAlways' => ENVIRONMENT === 'production' ? false : true));
        $compiler = $volt->getCompiler();
        $compiler->addFunction('_', function ($resolvedArgs, $exprArgs) use($di) {
            $translate = $di->get('translate');
            return $translate->trans($exprArgs, $resolvedArgs);
        });
        return $volt;
    }));
コード例 #8
0
ファイル: services.php プロジェクト: ricky49/darr_webpage
    return $sdk;
});
$di->set('router', function () use($config) {
    $request = new \Phalcon\Http\Request();
    return include __DIR__ . "/routes.php";
}, true);
/**
 * Setting up the view component
 */
$di->set('view', function () use($config) {
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir($config->application->viewsDir);
    return $view;
});
$di->set('viewSimple', function () use($config) {
    $view = new \Phalcon\Mvc\View\Simple();
    $view->setViewsDir($config->application->viewsDir);
    $view->registerEngines(['.volt' => function ($view, $di) {
        return new \Phalcon\Mvc\View\Engine\Volt($view, $di);
    }]);
    return $view;
});
$di->set('view', function () use($config) {
    $view = new View();
    $view->setViewsDir($config->application->viewsDir);
    $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
        $volt = new VoltEngine($view, $di);
        $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_', 'compileAlways' => true));
        //agregamos toda la sfuncoines de php
        $volt->getCompiler()->addExtension(new \App\Libraries\PhpFunctionExtension());
        return $volt;
コード例 #9
0
 public static function run()
 {
     if (in_array(APPLICATION_ENV, array('development'))) {
         $debug = new \Phalcon\Debug();
         $debug->listen();
     }
     $di = new \Phalcon\DI\FactoryDefault();
     $config = (include APPLICATION_PATH . '/config/application.php');
     $di->set('config', $config);
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces($config->loader->namespaces->toArray());
     $loader->register();
     $loader->registerDirs(array(APPLICATION_PATH . "/plugins/"));
     $db = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "charset" => $config->database->charset));
     $di->set('db', $db);
     $view = new View();
     /* $view->disableLevel(array(
        View::LEVEL_BEFORE_TEMPLATE => true,
        View::LEVEL_LAYOUT          => true,
        View::LEVEL_AFTER_TEMPLATE  => true
        )); */
     define('MAIN_VIEW_PATH', '../../../views/');
     $view->setMainView(MAIN_VIEW_PATH . 'main');
     $view->setLayoutsDir(MAIN_VIEW_PATH . '/layouts/');
     $view->setPartialsDir(MAIN_VIEW_PATH . '/partials/');
     $volt = new \Application\Mvc\View\Engine\Volt($view, $di);
     $volt->setOptions(array('compiledPath' => APPLICATION_PATH . '/cache/volt/'));
     $volt->initCompiler();
     $viewEngines = array(".volt" => $volt);
     $view->registerEngines($viewEngines);
     $di->set('view', $view);
     $viewSimple = new \Phalcon\Mvc\View\Simple();
     $viewSimple->registerEngines($viewEngines);
     $di->set('viewSimple', $viewSimple);
     $url = new \Phalcon\Mvc\Url();
     $url->setBasePath('/');
     $url->setBaseUri('/');
     $application = new \Phalcon\Mvc\Application();
     $application->registerModules($config->modules->toArray());
     $router = new \Application\Mvc\Router\DefaultRouter();
     foreach ($application->getModules() as $module) {
         $className = str_replace('Module', 'Routes', $module['className']);
         if (class_exists($className)) {
             $class = new $className();
             $router = $class->init($router);
         }
     }
     $di->set('router', $router);
     $eventsManager = new \Phalcon\Events\Manager();
     $dispatcher = new \Phalcon\Mvc\Dispatcher();
     $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
         new ExceptionPlugin($dispatcher, $exception);
     });
     $eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher) {
         new LocalizationPlugin($dispatcher);
     });
     $eventsManager->attach("acl", function ($event, $acl) {
         if ($event->getType() == 'beforeCheckAccess') {
             echo $acl->getActiveRole(), $acl->getActiveResource(), $acl->getActiveAccess();
         }
     });
     $dispatcher->setEventsManager($eventsManager);
     $di->set('dispatcher', $dispatcher);
     $session = new \Phalcon\Session\Adapter\Files();
     $session->start();
     $di->set('session', $session);
     $acl = new \Application\Acl\DefaultAcl();
     $acl->setEventsManager($eventsManager);
     $di->set('acl', $acl);
     $assets = new \Phalcon\Assets\Manager();
     $di->set('assets', $assets);
     $flash = new \Phalcon\Flash\Session(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning'));
     $di->set('flash', $flash);
     $di->set('helper', new \Application\Mvc\Helper());
     $application->setDI($di);
     echo $application->handle()->getContent();
 }
コード例 #10
0
ファイル: views-927.php プロジェクト: aodkrisda/phalcon-code
<?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));
コード例 #11
0
ファイル: gen-api.php プロジェクト: KevinJay/docs
    throw new Exception("Need to set CPHALCON_DIR. Fox example: 'export CPHALCON_DIR=/Users/gutierrezandresfelipe/cphalcon/ext/'");
}
if (!file_exists(CPHALCON_DIR)) {
    throw new Exception("CPHALCON directory does not exist");
}
$languagesConfigPath = "scripts/config/languages.json";
$languagesConfigContents = file_get_contents($languagesConfigPath);
$languages = json_decode($languagesConfigContents);
/**
 * 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;
コード例 #12
0
ファイル: views-439.php プロジェクト: aodkrisda/phalcon-code
<?php

$di->set('view', function () {
    $view = new Phalcon\Mvc\View\Simple();
    $view->setViewsDir('../app/views/');
    return $view;
}, true);
コード例 #13
0
ファイル: Bootstrap.php プロジェクト: 101010111100/yona-cms
 public function run()
 {
     $di = new \Phalcon\DI\FactoryDefault();
     $config = (include APPLICATION_PATH . '/config/application.php');
     $di->set('config', $config);
     $registry = new \Phalcon\Registry();
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces($config->loader->namespaces->toArray());
     $loader->register();
     $loader->registerDirs(array(APPLICATION_PATH . "/plugins/"));
     $db = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "charset" => $config->database->charset));
     $di->set('db', $db);
     $view = new \Phalcon\Mvc\View();
     define('MAIN_VIEW_PATH', '../../../views/');
     $view->setMainView(MAIN_VIEW_PATH . 'main');
     $view->setLayoutsDir(MAIN_VIEW_PATH . '/layouts/');
     $view->setPartialsDir(MAIN_VIEW_PATH . '/partials/');
     $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
     $volt->setOptions(array('compiledPath' => APPLICATION_PATH . '/cache/volt/'));
     $phtml = new \Phalcon\Mvc\View\Engine\Php($view, $di);
     $viewEngines = array(".volt" => $volt, ".phtml" => $phtml);
     $registry->viewEngines = $viewEngines;
     $view->registerEngines($viewEngines);
     if (isset($_GET['_ajax']) && $_GET['_ajax']) {
         $view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_LAYOUT);
     }
     $di->set('view', $view);
     $viewSimple = new \Phalcon\Mvc\View\Simple();
     $viewSimple->registerEngines($viewEngines);
     $di->set('viewSimple', $viewSimple);
     $url = new \Phalcon\Mvc\Url();
     $url->setBasePath('/');
     $url->setBaseUri('/');
     $cacheFrontend = new \Phalcon\Cache\Frontend\Data(array("lifetime" => 60, "prefix" => HOST_HASH));
     switch ($config->cache) {
         case 'file':
             $cache = new \Phalcon\Cache\Backend\File($cacheFrontend, array("cacheDir" => __DIR__ . "/cache/backend/"));
             break;
         case 'memcache':
             $cache = new \Phalcon\Cache\Backend\Memcache($cacheFrontend, array("host" => "localhost", "port" => "11211"));
             break;
     }
     $di->set('cache', $cache);
     $di->set('modelsCache', $cache);
     switch ($config->metadata_cache) {
         case 'memory':
             $modelsMetadata = new \Phalcon\Mvc\Model\Metadata\Memory();
             break;
         case 'apc':
             $modelsMetadata = new \Phalcon\Mvc\Model\MetaData\Apc(array("lifetime" => 60, "prefix" => HOST_HASH));
             break;
     }
     $di->set('modelsMetadata', $modelsMetadata);
     /**
      * CMS Конфигурация
      */
     $cmsModel = new \Cms\Model\Configuration();
     $cms = $cmsModel->getConfig();
     // @todo Будет отдельный раздел конфигурации для управления языками. Пока заглушка.
     $cms['languages'] = [['name' => 'Русский', 'iso' => 'ru', 'locale' => 'ru_RU'], ['name' => 'English', 'iso' => 'en', 'locale' => 'en_EN']];
     $registry->cms = $cms;
     // Отправляем в Registry
     $application = new \Phalcon\Mvc\Application();
     $application->registerModules($config->modules->toArray());
     $router = new \Application\Mvc\Router\DefaultRouter();
     foreach ($application->getModules() as $module) {
         $className = str_replace('Module', 'Routes', $module['className']);
         if (class_exists($className)) {
             $class = new $className();
             $router = $class->init($router);
         }
     }
     $di->set('router', $router);
     $eventsManager = new \Phalcon\Events\Manager();
     $dispatcher = new \Phalcon\Mvc\Dispatcher();
     $eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher, $di) use($di) {
         new LocalizationPlugin($dispatcher);
         new AclPlugin($di->get('acl'), $dispatcher);
     });
     $profiler = new \Phalcon\Db\Profiler();
     $eventsManager->attach('db', function ($event, $db) use($profiler) {
         if ($event->getType() == 'beforeQuery') {
             $profiler->startProfile($db->getSQLStatement());
         }
         if ($event->getType() == 'afterQuery') {
             $profiler->stopProfile();
         }
     });
     $db->setEventsManager($eventsManager);
     $di->set('profiler', $profiler);
     $dispatcher->setEventsManager($eventsManager);
     $di->set('dispatcher', $dispatcher);
     $session = new \Phalcon\Session\Adapter\Files();
     $session->start();
     $di->set('session', $session);
     $acl = new \Application\Acl\DefaultAcl();
     $di->set('acl', $acl);
     $assets = new \Phalcon\Assets\Manager();
     $di->set('assets', $assets);
     $flash = new \Phalcon\Flash\Session(array('error' => 'ui red inverted segment', 'success' => 'ui green inverted segment', 'notice' => 'ui blue inverted segment', 'warning' => 'ui orange inverted segment'));
     $di->set('flash', $flash);
     $di->set('helper', new \Application\Mvc\Helper());
     $di->set('registry', $registry);
     $assetsManager = new \Phalcon\Assets\Manager();
     $di->set('assets', $assetsManager);
     $application->setDI($di);
     $this->dispatch($di);
 }