private function setView($manager, $theme)
 {
     /* ==================================================
      * ตั้งค่าเรียกใช้งานไฟล์ View ทั้งหมด
      * Setting up the view component
      * ================================================== */
     $manager->set('view', function () use($theme) {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         /* ตำแหน่งเก็บไฟล์ views ทั้งหมด */
         $view->setLayoutsDir(sprintf('%s/%s/', $this->config->theme->themesDir, $theme));
         /* ตำแหน่งเก็บไฟล์ layouts ทั้งหมด */
         $view->setTemplateAfter('layouts/' . $this->layoutName);
         /* เลือกไฟล์ layout เริ่มต้น*/
         /* สร้างโฟล์เดอร์เก็บไฟล์ cache */
         $cacheDir = sprintf('%s/%s/%s/', APPLICATION_PATH, $this->config->application->cacheDir, $this->moduleName);
         if (!is_dir($cacheDir)) {
             mkdir($cacheDir);
         }
         $view->registerEngines(array('.phtml' => function ($view, $di) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => sprintf('%s/%s/%s/', APPLICATION_PATH, $this->config->application->cacheDir, $this->moduleName), 'compiledSeparator' => '_'));
             return $volt;
         }));
         return $view;
     });
 }
Example #2
0
 public function registerServices(DiInterface $di)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     $di['dispatcher'] = function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Modules\\Backend\\Controllers");
         return $dispatcher;
     };
     /**
      * Setting up the view component
      */
     $di['view'] = function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setLayoutsDir('../../common/layouts/backend/');
         $view->setTemplateAfter('main');
         return $view;
     };
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di['db'] = function () use($config) {
         return new MySQLAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name));
     };
 }
Example #3
0
 public function testStandardRender()
 {
     $view = new View();
     $view->setBasePath(__DIR__ . '/../');
     $view->setViewsDir('unit-tests/views/');
     $this->assertEquals($view->getViewsDir(), 'unit-tests/views/');
     //Standard Render
     $view->start();
     $view->render('test2', 'index');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>here</html>' . PHP_EOL);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
     //Variables
     $view->setParamToView('a_cool_var', 'le-this');
     $view->start();
     $view->render('test3', 'another');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lol<p>le-this</p></html>' . PHP_EOL);
     //Templates
     $view->setTemplateAfter('test');
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>zuplolhere</html>' . PHP_EOL);
     $view->cleanTemplateAfter();
     //Render Levels
     $view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
     $view->setRenderLevel(View::LEVEL_LAYOUT);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), 'lolhere');
     $view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), 'here');
     //Pick View
     $view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
     $view->start();
     $view->pick('test3/yup');
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolyup</html>' . PHP_EOL);
     //No Render
     $view->setRenderLevel(View::LEVEL_NO_RENDER);
     $view->start();
     $view->pick('test3/yup');
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '');
 }
Example #4
0
 /**
  * Registers services related to the module
  *
  * @param DiInterface $di        	
  */
 public function registerServices(DiInterface $di)
 {
     /**
      * Read configuration
      */
     $config = new Ini(APP_PATH . "/apps/teacher/config/config.ini");
     /**
      * Setting up the view component
      */
     $di['view'] = function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         // set layout
         $view->setLayoutsDir('../../../layouts/');
         $view->setTemplateAfter('main');
         return $view;
     };
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di['db'] = function () use($config) {
         return new DbAdapter(array('host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname));
     };
 }
Example #5
0
 /**
  * @param \Phalcon\DI\FactoryDefault     $di
  */
 protected function registerViewService($di)
 {
     /**
      * Setting up the view component
      */
     $di['view'] = function () use($di) {
         /*
          * Obtengo el nombre del modulo para poder obner el archivo de configuracion
          */
         $module = $this->name;
         $this->layout_dir = '../../../../public/layouts/' . $di->get('modules')->{$module}->layout . '/';
         $view = new View();
         $view->setViewsDir($this->path . $this->view_dir);
         $view->setLayoutsDir($this->layout_dir);
         $view->setTemplateAfter($this->template);
         $view->setVar('project-setting', $di->get('config')->project->toArray());
         /*
          * Registra Constantes de Modulo
          */
         $view->setVar('module-setting', $di->get('modules')->{$module}->toArray());
         // Set the engine
         $view->registerEngines(array(".mustache" => function ($view, DI $di) {
             $module = $this->name;
             $partial_url = '../public/layouts/' . $di->get('modules')->{$module}->layout . '/partials';
             $partial_loader = new Mustache_Loader_FilesystemLoader($partial_url);
             $config = $di->get('config')->cache->frontend;
             if ($config->active == 0) {
                 $options = array('partials_loader' => $partial_loader);
             } else {
                 $options = array('cache' => '/var/www/var/cache/elephant', 'cache_file_mode' => $config->mode, 'partials_loader' => $partial_loader, 'strict_callables' => $config->callables);
             }
             $mustache = new Mustache($view, $di, $options);
             return $mustache;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         return $view;
     };
 }
Example #6
0
 protected function _getViewDisabled($level = null)
 {
     $view = new Phalcon\Mvc\View();
     $view->setViewsDir('unit-tests/views/');
     $view->setTemplateAfter('after');
     $view->setTemplateBefore('before');
     if ($level !== null) {
         $view->disableLevel($level);
     }
     $view->start();
     $view->render('test13', 'index');
     $view->finish();
     return $view;
 }
Example #7
0
 public function testIssue907()
 {
     $view = new View();
     $view->setBasePath(__DIR__ . '/../');
     $view->setViewsDir('unit-tests/views/');
     $listener = new \ViewAfterRenderListener();
     $eventsManager = new \Phalcon\Events\Manager();
     $eventsManager->attach('view', $listener);
     $view->setEventsManager($eventsManager);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
     $this->assertEquals('1,3,6', $listener->getLevels());
     $listener->reset();
     //Templates
     $view->setTemplateAfter('test');
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>zuplolhere</html>' . PHP_EOL);
     $this->assertEquals('1,3,5,6', $listener->getLevels());
     $listener->reset();
     $view->cleanTemplateAfter();
     //Render Levels
     $view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
     $this->assertEquals('1,3,6', $listener->getLevels());
     $listener->reset();
     $view->setRenderLevel(View::LEVEL_LAYOUT);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), 'lolhere');
     $this->assertEquals('1,3', $listener->getLevels());
     $listener->reset();
     $view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), 'here');
     $this->assertEquals('1', $listener->getLevels());
     $listener->reset();
 }
Example #8
0
/**
 * The URL component is used to generate all kinds of URLs in the application
 */
$di->setShared('url', function () use($config) {
    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);
    return $url;
});
/**
 * Setting up the view component
 */
$di->setShared('view', function () use($config) {
    $view = new View();
    $view->setViewsDir($config->application->viewsDir);
    $view->setLayoutsDir('../../common/layouts/');
    $view->setTemplateAfter('main');
    $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
        $volt = new VoltEngine($view, $di);
        $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_', 'stat' => true, 'compileAlways' => true));
        return $volt;
    }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
    return $view;
});
/**
 * Database connection is created based in the parameters defined in the configuration file
 */
$di->setShared('db', function () use($config) {
    $dbConfig = $config->database->toArray();
    $adapter = $dbConfig['adapter'];
    unset($dbConfig['adapter']);
    $class = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter;
    $dispatcher->setEventsManager($eventsManager);
    return $dispatcher;
});
/* ==================================================
 * ตั้งค่าการเชื่อมต่อฐานข้อมูล
 * ================================================== */
$manager->set('db', function () {
    return new DbAdapter(array('host' => $this->config->database->host, 'username' => $this->config->database->username, 'password' => $this->config->database->password, 'dbname' => $this->config->database->dbname, 'options' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->config->database->charset)));
});
$manager->set('view', function () {
    $view = new View();
    $view->setViewsDir(__DIR__ . '/views/');
    /* ตำแหน่งเก็บไฟล์ views ทั้งหมด */
    $view->setLayoutsDir(sprintf('%s/%s/', $this->config->theme->themesDir, $this->config->theme->themeDefault));
    /* ตำแหน่งเก็บไฟล์ layouts ทั้งหมด */
    $view->setTemplateAfter('layouts/' . $this->config->theme->layoutDefault);
    /* เลือกไฟล์ layout เริ่มต้น*/
    /* สร้างโฟล์เดอร์เก็บไฟล์ cache */
    $cacheDir = sprintf('%s/%s/', APPLICATION_PATH, $this->config->application->cacheDir);
    if (!is_dir($cacheDir)) {
        mkdir($cacheDir);
    }
    $view->registerEngines(array('.phtml' => function ($view, $di) {
        $volt = new VoltEngine($view, $di);
        $volt->setOptions(array('compiledPath' => sprintf('%s/%s/', APPLICATION_PATH, $this->config->application->cacheDir), 'compiledSeparator' => '_'));
        return $volt;
    }));
    return $view;
});
/* ==================================================
 * ตั้งค่าการเปิดใช้งาน Session
Example #10
0
 protected function _getViewDisabled($level = null)
 {
     $view = new View();
     $view->setViewsDir(PATH_DATA . "views" . DIRECTORY_SEPARATOR);
     $view->setTemplateAfter("after");
     $view->setTemplateBefore("before");
     if ($level !== null) {
         $view->disableLevel($level);
     }
     $view->start();
     $view->render("test13", "index");
     $view->finish();
     return $view;
 }