示例#1
0
 public function run()
 {
     $di = new \Phalcon\DI\FactoryDefault();
     // Config
     require_once APPLICATION_PATH . '/modules/Cms/Config.php';
     $config = \Cms\Config::get();
     $di->set('config', $config);
     // Registry
     $registry = new \Phalcon\Registry();
     $di->set('registry', $registry);
     // Loader
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces($config->loader->namespaces->toArray());
     $loader->registerDirs([APPLICATION_PATH . "/plugins/"]);
     $loader->register();
     require_once APPLICATION_PATH . '/../vendor/autoload.php';
     // Database
     $db = new \Phalcon\Db\Adapter\Pdo\Mysql(["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
     $this->initView($di);
     // URL
     $url = new \Phalcon\Mvc\Url();
     $url->setBasePath($config->base_path);
     $url->setBaseUri($config->base_path);
     $di->set('url', $url);
     // Cache
     $this->initCache($di);
     // CMS
     $cmsModel = new \Cms\Model\Configuration();
     $registry->cms = $cmsModel->getConfig();
     // Отправляем в Registry
     // Application
     $application = new \Phalcon\Mvc\Application();
     $application->registerModules($config->modules->toArray());
     // Events Manager, Dispatcher
     $this->initEventManager($di);
     // Session
     $session = new \Phalcon\Session\Adapter\Files();
     $session->start();
     $di->set('session', $session);
     $acl = new \Application\Acl\DefaultAcl();
     $di->set('acl', $acl);
     // JS Assets
     $this->initAssetsManager($di);
     // Flash helper
     $flash = new \Phalcon\Flash\Session(['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());
     // Routing
     $this->initRouting($application, $di);
     $application->setDI($di);
     // Main dispatching process
     $this->dispatch($di);
 }
示例#2
0
 public function setUp()
 {
     $di = new Phalcon\DI();
     $di->set('url', function () {
         $url = new Phalcon\Mvc\Url();
         $url->setBaseUri('/');
         return $url;
     });
     $this->_response = new Phalcon\Http\Response();
     $this->_response->setDI($di);
 }
示例#3
0
 /**
  * @return mixed
  */
 public function cache()
 {
     $path = $this->buildPath();
     if ($path) {
         if ($this->createOrNone() || !file_exists($path)) {
             $this->save($path);
         }
     }
     $url = new \Phalcon\Mvc\Url();
     return $url->path($path);
 }
 protected function registerConfiguration()
 {
     $env = new \Phalcon\Config\Adapter\Ini(ROOT_PATH . "/env.ini");
     $this->di->set('env', function () use($env) {
         return $env;
     });
     $this->di->set('url', function () use($env) {
         $url = new \Phalcon\Mvc\Url();
         $url->setBaseUri("{$env->application->protocol}://{$env->application->base_uri}/");
         return $url;
     });
 }
示例#5
0
 /**
  * Initializes the baseUrl
  */
 public function init()
 {
     $di = $this->getDi();
     $eventsManager = $this->getEventsManager();
     /**
      * The URL component is used to generate all kind of urls in the
      * application
      */
     $url = new \Phalcon\Mvc\Url();
     $url->setBaseUri($this->_config->application->baseUri);
     $di->set('url', $url);
 }
示例#6
0
文件: index.php 项目: abuelezz/mvc
 /**
  * Register the services here to make them general or register in
  * the ModuleDefinition to make them module-specific.
  */
 protected function _registerServices()
 {
     $loader = new \Phalcon\Loader();
     /**
      * We're a registering a set of directories taken from the configuration file
      */
     /*
     $loader->registerDirs(
             array(
                     __DIR__ . '/../library/',
                     __DIR__ . '/../vendor/',
             )
     )->register();
     */
     // Init a DI
     $di = new \Phalcon\DI\FactoryDefault();
     // Registering a router:
     $defaultModule = self::DEFAULT_MODULE;
     $modules = self::$modules;
     $di->set('router', function () use($defaultModule, $modules) {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule($defaultModule);
         foreach ($modules as $moduleName => $module) {
             // do not route default module
             if ($defaultModule == $moduleName) {
                 continue;
             }
             $router->add('#^/' . $moduleName . '(|/)$#', array('module' => $moduleName, 'controller' => 'index', 'action' => 'index'));
             $router->add('#^/' . $moduleName . '/([a-zA-Z0-9\\_]+)[/]{0,1}$#', array('module' => $moduleName, 'controller' => 1));
             $router->add('#^/' . $moduleName . '[/]{0,1}([a-zA-Z0-9\\_]+)/([a-zA-Z0-9\\_]+)(/.*)*$#', array('module' => $moduleName, 'controller' => 1, 'action' => 2, 'params' => 3));
         }
         return $router;
     });
     /**
      * The URL component is used to generate all kind of urls in the application
      */
     $di['url'] = function () {
         $url = new \Phalcon\Mvc\Url();
         $url->setBaseUri('/');
         return $url;
     };
     /**
      * Start the session the first time some component request the session service
      */
     $di['session'] = function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     };
     $this->setDI($di);
 }
示例#7
0
 public static function setUpBeforeClass()
 {
     $basedir = realpath(__DIR__ . '/../../');
     $testdir = $basedir . '/tests';
     self::$viewsdir = realpath($testdir . '/views/') . '/';
     include_once $basedir . "/vendor/autoload.php";
     $di = new DI();
     $di->set('form', "Logikos\\Forms\\Form");
     $di->set('url', function () {
         $url = new \Phalcon\Mvc\Url();
         $url->setBaseUri('/');
         return $url;
     });
     static::$di = $di;
 }
示例#8
0
 public function testUrl()
 {
     Phalcon\DI::reset();
     //Create a default DI
     $di = new Phalcon\DI();
     $di['router'] = function () {
         $router = new \Phalcon\Mvc\Router(FALSE);
         $router->add('/:controller/:action', array('controller' => 1, 'action' => 2))->setHostName('phalconphp.com')->setName('test');
         return $router;
     };
     $di->set('url', function () {
         $url = new Phalcon\Mvc\Url();
         $url->setBaseUri('/');
         return $url;
     });
     $url = $di->url->get(array('for' => 'test', 'hostname' => true, 'controller' => 'index', 'action' => 'test'));
     $this->assertEquals($url, 'phalconphp.com/index/test');
 }
示例#9
0
 /**
  * Sets the test up by loading the DI container and other stuff
  *
  * @author Nikos Dimopoulos <*****@*****.**>
  * @since  2012-09-30
  *
  * @return \Phalcon\DI
  */
 protected function setUp()
 {
     $this->checkExtension('phalcon');
     // Set the config up
     $this->config = Config::init();
     // Reset the DI container
     \Phalcon\DI::reset();
     // Instantiate a new DI container
     $di = new \Phalcon\DI();
     // Set the URL
     $di->set('url', function () {
         $url = new \Phalcon\Mvc\Url();
         $url->setBaseUri('/');
         return $url;
     });
     $di->set('escaper', function () {
         return new \Phalcon\Escaper();
     });
     $this->di = $di;
 }
 /**
  * Register specific services for the module
  */
 public function registerServices($di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Blog\\Frontend\\Controllers");
         return $dispatcher;
     });
     $di->set('url', function () {
         $url = new \Phalcon\Mvc\Url();
         $url->setBaseUri('/blog/');
         return $url;
     });
     //Registering the view component
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir('../apps/frontend/views/');
         $view->registerEngines(array(".phtml" => 'Phalcon\\Mvc\\View\\Engine\\Volt'));
         return $view;
     });
 }
示例#11
0
 /**
  * Configuración de la base URI, para generar automaticacmente todas las direcciones posibles dentro de la carpeta 
  * principal de la aplicación
  * @return DI object
  */
 private function setUri()
 {
     $urlManagerObj = $this->urlManager;
     $this->di->set('url', function () use($urlManagerObj) {
         $url = new \Phalcon\Mvc\Url();
         $uri = $urlManagerObj->getBaseUri();
         // Adicionar / al inicio y al final
         if (substr($uri, 0, 1) != '/') {
             $uri = '/' . $uri;
         }
         if (substr($uri, -1) != '/') {
             $uri .= '/';
         }
         $url->setBaseUri($uri);
         return $url;
     });
 }
示例#12
0
 public function testFilterMultiplesSourcesFilterJoin()
 {
     @unlink(__DIR__ . '/assets/production/combined-3.js');
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di['url'] = function () {
         $url = new Phalcon\Mvc\Url();
         $url->setStaticBaseUri('/');
         return $url;
     };
     $assets = new Phalcon\Assets\Manager();
     $assets->useImplicitOutput(false);
     $js = $assets->collection('js');
     $js->setTargetUri('production/combined-3.js');
     $js->setTargetPath(__DIR__ . '/assets/production/combined-3.js');
     $jquery = new Phalcon\Assets\Resource\Js(__DIR__ . '/assets/jquery.js', false, false);
     $jquery->setTargetUri('jquery.js');
     $js->add($jquery);
     $gs = new Phalcon\Assets\Resource\Js(__DIR__ . '/assets/gs.js');
     $gs->setTargetUri('gs.js');
     $gs->setTargetPath('gs.js');
     $js->add($gs);
     $js->join(true);
     //Use two filters
     $js->addFilter(new Phalcon\Assets\Filters\None());
     $js->addFilter(new Phalcon\Assets\Filters\None());
     $this->assertEquals($assets->outputJs('js'), '<script src="/production/combined-3.js" type="text/javascript"></script>' . PHP_EOL);
 }
示例#13
0
 $loader = new \Phalcon\Loader();
 $loader->registerDirs(array('../app/controllers/', '../app/models/', '../app/forms/', '../app/views/', '../app/plugins/', '../app/wrappers/'));
 $loader->registerNamespaces(array('Silar\\Misc' => '../app/misc/'), true);
 $loader->register();
 //Create a DI
 $di = new Phalcon\DI\FactoryDefault();
 //Registering Volt as template engine
 $di->set('view', function () {
     $view = new \Phalcon\Mvc\View();
     $view->setViewsDir('../app/views/');
     $view->registerEngines(array(".volt" => 'Phalcon\\Mvc\\View\\Engine\\Volt'));
     return $view;
 });
 //Setup a base URI so that all generated URIs include the "tutorial" folder
 $di->set('url', function () {
     $url = new \Phalcon\Mvc\Url();
     $url->setBaseUri('/silar/');
     return $url;
 });
 $di->setShared('session', function () {
     $session = new Phalcon\Session\Adapter\Files();
     $session->start();
     return $session;
 });
 $di->set('router', function () {
     $router = new \Phalcon\Mvc\Router\Annotations();
     $router->addResource('Api', '/api');
     return $router;
 });
 $di->set('db', function () use($config) {
     return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname));
示例#14
0
文件: index.php 项目: Riu/kirocms
    if (!empty($routers)) {
        foreach ($routers as $name => $rule) {
            $pattern = $rule->pattern;
            unset($rule->pattern);
            $router->add($pattern, $rule->toArray())->setName($name);
        }
    }
    return $router;
});
$di->setShared('db', function () use($config) {
    $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name, "charset" => $config->database->charset, "collation" => $config->database->collation));
    return $connection;
});
$di->set('modelsManager', new \Phalcon\Mvc\Model\Manager());
$di->setShared('url', function () use($config) {
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri($config->app->base);
    return $url;
});
try {
    $application = new Phalcon\Mvc\Application();
    $application->setDI($di);
    if (!empty($config->apps)) {
        foreach ($config->apps as $name => $app) {
            $apps[$name] = array('className' => $app . '\\Module', 'path' => '../' . $config->app->apps . $name . DIRECTORY_SEPARATOR . 'Module.php');
        }
    }
    $application->registerModules($apps);
    echo $application->handle()->getContent();
} catch (Exception $e) {
    echo $e->getMessage();
示例#15
0
 });
 $di->setShared('volt', function ($view, $di) {
     $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
     $volt->setOptions(array("compileAlways" => true, "compiledPath" => "../app/compiled-templates/", 'stat' => true));
     $compiler = $volt->getCompiler();
     return $volt;
 });
 $di->set('logger', function () {
     // Archivo de log
     return new \Phalcon\Logger\Adapter\File("../app/logs/debug.log");
 });
 $urlManager = new \Sigmamovil\Misc\UrlManager($config);
 $di->set('urlManager', $urlManager);
 //Setup a base URI so that all generated URIs include the "tutorial" folder
 $di->set('url', function () use($urlManager) {
     $url = new \Phalcon\Mvc\Url();
     $uri = $urlManager->get_base_uri();
     // Adicionar / al inicio y al final
     if (substr($uri, 0, 1) != '/') {
         $uri = '/' . $uri;
     }
     if (substr($uri, -1) != '/') {
         $uri .= '/';
     }
     $url->setBaseUri($uri);
     return $url;
 });
 $di->setShared('session', function () {
     $session = new Phalcon\Session\Adapter\Files();
     $session->start();
     return $session;
示例#16
0
文件: index.php 项目: boiler256/mvc
 $di = new \Phalcon\DI\FactoryDefault();
 /**
  * Registering a router
  */
 $di['router'] = function () {
     $router = new \Phalcon\Mvc\Router(false);
     $router->add('/admin', array('module' => 'backend', 'controller' => 'index', 'action' => 'index'));
     $router->add('/index', array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
     $router->add('/', array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
     return $router;
 };
 /**
  * The URL component is used to generate all kind of urls in the application
  */
 $di->set('url', function () {
     $url = new \Phalcon\Mvc\Url();
     $url->setBaseUri('/mvc/multiple-shared-layouts/');
     return $url;
 });
 /**
  * Start the session the first time some component request the session service
  */
 $di->set('session', function () {
     $session = new \Phalcon\Session\Adapter\Files();
     $session->start();
     return $session;
 });
 /**
  * Handle the request
  */
 $application = new \Phalcon\Mvc\Application();
<?php

// Tuning up components for the module dependencies BackEnd
// Component URL is used to generate all kinds of addresses in the annex
$di->set('url', function () {
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri($this->_config->application->baseUri)->setBasePath(DOCUMENT_ROOT);
    return $url;
});
// Database connection is created based in the parameters defined in the configuration file
$di->setShared('db', function () {
    try {
        $connect = new \Phalcon\Db\Adapter\Pdo\Mysql(["host" => $this->_config->database->host, "username" => $this->_config->database->username, "password" => $this->_config->database->password, "dbname" => $this->_config->database->dbname, "persistent" => $this->_config->database->persistent, "options" => [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES '{$this->_config->database->charset}'", PDO::ATTR_CASE => PDO::CASE_LOWER, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]]);
        return $connect;
    } catch (PDOException $e) {
        throw new Exception('Could not connect to database');
    }
});
// Component Session. Starting a Session
$di->setShared('session', function () {
    $session = new Phalcon\Session\Adapter\Memcache(['host' => $this->_config->cache->memcached->host, 'port' => $this->_config->cache->memcached->port, 'lifetime' => $this->_config->cache->lifetime, 'prefix' => $this->_config->cache->prefix, 'persistent' => false]);
    $session->start();
    return $session;
});
// Component Logger. $this->di->get('logger')->log('.....',Logger::ERROR);
$di->setShared('logger', function () {
    if ($this->_config->logger->enable == true) {
        $formatter = new \Phalcon\Logger\Formatter\Line($this->_config->logger->format);
        $logger = new \Phalcon\Logger\Adapter\File($this->_config->logger->file);
        $logger->setFormatter($formatter);
        return $logger;
示例#18
0
<?php

use Phalcon\Mvc\Dispatcher;
/**
 * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
 */
$di = new \Phalcon\DI\FactoryDefault();
/**
 * The URL component is used to generate all kind of urls in the application
 */
$di->set('url', function () use($config) {
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri($config->application->baseUri);
    return $url;
});
/**
 * Setting up the view component
 */
$di->set('view', function () use($config) {
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir($config->application->viewsDir);
    return $view;
});
// Registering a dispatcher
$di->set('dispatcher', function () {
    $dispatcher = new Dispatcher();
    $dispatcher->setDefaultNamespace("App\\Controllers");
    return $dispatcher;
});
/**
 * Database connection is created based in the parameters defined in the configuration file
示例#19
0
文件: index.php 项目: chyro/Lifestyle
        $dispatcher->setDefaultNamespace('Watchlist\\Controllers');
        return $dispatcher;
    });
    //Setup the flash service
    $config["di"]->set('flash', function () {
        return new \Phalcon\Flash\Direct();
    });
    //Route Settings
    include "../app/config/routes.php";
    //DB Settings
    $config["di"]->set('mongo', function () use($config) {
        $mongo = new MongoClient();
        return $mongo->selectDB($config->database->name);
    }, true);
    $config["di"]->set('collectionManager', function () {
        return new \Phalcon\Mvc\Collection\Manager();
    }, true);
    $config["di"]->set('url', function () {
        $url = new \Phalcon\Mvc\Url();
        $url->setBaseUri('/');
        return $url;
    });
    //Handle the request
    $application = new \Phalcon\Mvc\Application($config["di"]);
    echo $application->handle()->getContent();
} catch (\Phalcon\Exception $e) {
    echo "\\PhalconException: ", $e->getMessage();
    echo "<pre>";
    var_dump($e->getTrace());
    echo "</pre>";
}
示例#20
0
    echo 'Unable to load config file';
    die;
}
//-
error_reporting($config['errors']['level']);
ini_set('display_errors', $config['errors']['display']);
//-
date_default_timezone_set($config['application']['timezone']);
//-
define('ASSETS_URL', $config['assets']['url']);
define('BASE_URL', $config['application']['baseUrl']);
try {
    $di = new \Phalcon\DI\FactoryDefault();
    // The URL component is used to generate all kind of urls in the application
    $di->set('url', function () use($config) {
        $url = new \Phalcon\Mvc\Url();
        $url->setBaseUri($config['application']['baseUrl']);
        return $url;
    });
    // Defining the APC adapter to improve the php and phalcon models speed
    $di->set('modelsMetadata', function () {
        // Create a meta-data manager with APC
        $metaData = new \Phalcon\Mvc\Model\MetaData\Apc(array('lifetime' => 86400, 'suffix' => 'my_application'));
        return $metaData;
    });
    // Database connection is created based in the parameters defined in the configuration file
    $di->set('db', function () use($config) {
        $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array('host' => $config['database']['general']['host'], 'username' => $config['database']['general']['username'], 'password' => $config['database']['general']['password'], 'dbname' => $config['database']['general']['dbname'], 'port' => $config['database']['general']['port']));
        return $connection;
    });
    // Setting the views path
示例#21
0
$di->set('flash', function () {
    $flash = new \Phalcon\Flash\Direct(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info'));
    return $flash;
});
/**
 * Navigation
 */
$di->set('navigation', function () {
    $navigation = new app\library\navigation\navigation();
    return $navigation;
});
/**
 * URL
 */
$di->set('url', function () {
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri('/');
    $url->setStaticBaseUri('/');
    return $url;
});
/**
 * Encryption
 */
$di->set('crypt', function () use($config) {
    $crypt = new Phalcon\Crypt();
    $crypt->setKey($config->encryption->key);
    return $crypt;
});
/**
 * Cookie
 */
示例#22
0
 /**
  * Set the url service
  *
  * @return void
  */
 protected function url()
 {
     $config = $this->_config;
     $this->_di->set('url', function () use($config) {
         $url = new \Phalcon\Mvc\Url();
         $url->setBaseUri($config->app->base_uri);
         $url->setStaticBaseUri($config->app->static_uri);
         return $url;
     });
 }
示例#23
0
<?php

$di->set('url', function () {
    $url = new Phalcon\Mvc\Url();
    $url->setBaseUri('/invo/');
    return $url;
});
示例#24
0
<?php

date_default_timezone_set('America/Mexico_City');
ini_set('display_errors', true);
error_reporting(E_ALL);
$di = new \Phalcon\DI\FactoryDefault();
$di->set('url', function () {
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri("http://" . $_SERVER["SERVER_NAME"] . "/");
    return $url;
});
$di->set('router', function () {
    $router = new \Phalcon\Mvc\Router();
    $router->setDefaultModule("frontend");
    $router->add("/", array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
    $router->add("/contactanos", array('module' => 'frontend', 'controller' => 'index', 'action' => 'contactanos'));
    $router->add("/token", array('module' => 'frontend', 'controller' => 'index', 'action' => 'token'));
    $router->notFound(array('module' => 'frontend', 'controller' => 'index', 'action' => 'show404'));
    /* Dashboard */
    $router->add("/dashboard", array('module' => 'dashboard', 'controller' => 'index', 'action' => 'index'));
    $router->add("/login", array('module' => 'dashboard', 'controller' => 'login', 'action' => 'index'));
    $router->add("/logout", array('module' => 'dashboard', 'controller' => 'login', 'action' => 'logout'));
    $router->add('/dashboard/([a-zA-Z\\-]+)/([a-zA-Z\\-]+)', array('module' => 'dashboard', 'controller' => 1, 'action' => 2))->setName("controllers")->convert('action', function ($action) {
        return \Phalcon\Text::lower(\Phalcon\Text::camelize($action));
    });
    $router->removeExtraSlashes(true);
    return $router;
});
/**
 * Start the session the first time some component request the session service
 */
示例#25
0
 //Create a DI
 $di = new Phalcon\DI\FactoryDefault();
 //Setup the database service
 $di->set('db', function () use($config) {
     return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name, 'charset' => 'UTF8'));
 });
 //Setup the view component
 $di->set('view', function () use($config) {
     $view = new \Phalcon\Mvc\View();
     $view->setViewsDir($config->application->viewsDir);
     $view->registerEngines(array(".phtml" => 'Phalcon\\Mvc\\View\\Engine\\Php', ".volt" => 'volt'));
     return $view;
 });
 //Setup a base URI so that all generated URIs include the "tutorial" folder
 $di->set('url', function () use($config) {
     $url = new \Phalcon\Mvc\Url();
     $url->setBaseUri($config->resource->baseUri);
     return $url;
 });
 //Start the session the first time when some component request the session service
 $di->setShared('session', function () {
     $session = new Phalcon\Session\Adapter\Files();
     $session->start();
     return $session;
 });
 $di->set('elements', function () {
     return new Elements();
 });
 /**
  * Setting up volt
  */
示例#26
0
<?php

try {
    //Enregistrement d'un autoloader pour premettre l'inclusion auto des fichiers de classe
    $loader = new \Phalcon\Loader();
    $loader->registerDirs(array('../app/controllers/', '../app/models/'))->register();
    //DI est le service responsable de l'injection de dépendance des services Phalcon utilisés
    $di = new Phalcon\DI\FactoryDefault();
    //Configuration des vues
    $di->set('view', function () {
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir('../app/views/');
        return $view;
    });
    //Configuration de l'URL de base
    $di->set('url', function () {
        $url = new \Phalcon\Mvc\Url();
        $url->setBaseUri('/TD1/firstPhalcon/');
        return $url;
    });
    //Interception de la requête pour routage et dispatching
    $application = new \Phalcon\Mvc\Application($di);
    echo $application->handle()->getContent();
} catch (\Phalcon\Exception $e) {
    echo "PhalconException: ", $e->getMessage();
}
示例#27
0
 /**
  * Execute Phalcon Developer Tools
  *
  * @param  string             $path The path to the Phalcon Developer Tools
  * @param  string             $ip   Optional IP address for securing Developer Tools
  * @return void
  * @throws \Exception         if Phalcon extension is not installed
  * @throws \Exception         if Phalcon version is not compatible Developer Tools
  * @throws \Phalcon\Exception if Application config could not be loaded
  */
 public static function main($path, $ip = null)
 {
     if (!extension_loaded('phalcon')) {
         throw new \Exception('Phalcon extension is not installed, follow these instructions to install it: http://phalconphp.com/documentation/install');
     }
     if ($ip !== null) {
         self::$ip = $ip;
     }
     if (!defined('TEMPLATE_PATH')) {
         define('TEMPLATE_PATH', $path . '/templates');
     }
     chdir('..');
     // Read configuration
     $configPaths = array('config', 'app/config', 'apps/frontend/config');
     $readed = false;
     foreach ($configPaths as $configPath) {
         $cpath = $configPath . '/config.ini';
         if (file_exists($cpath)) {
             $config = new \Phalcon\Config\Adapter\Ini($cpath);
             $readed = true;
             break;
         } else {
             $cpath = $configPath . '/config.php';
             if (file_exists($cpath)) {
                 $config = (require $cpath);
                 $readed = true;
                 break;
             }
         }
     }
     if ($readed === false) {
         throw new \Phalcon\Exception('Configuration file could not be loaded!');
     }
     $loader = new \Phalcon\Loader();
     $loader->registerDirs(array($path . '/scripts/', $path . '/scripts/Phalcon/Web/Tools/controllers/'));
     $loader->registerNamespaces(array('Phalcon' => $path . '/scripts/'));
     $loader->register();
     if (Version::getId() < Script::COMPATIBLE_VERSION) {
         throw new \Exception('Your Phalcon version is not compatible with Developer Tools, download the latest at: http://phalconphp.com/download');
     }
     try {
         $di = new FactoryDefault();
         $di->set('view', function () use($path) {
             $view = new View();
             $view->setViewsDir($path . '/scripts/Phalcon/Web/Tools/views/');
             return $view;
         });
         $di->set('config', $config);
         $di->set('url', function () use($config) {
             $url = new \Phalcon\Mvc\Url();
             $url->setBaseUri($config->application->baseUri);
             return $url;
         });
         $di->set('flash', function () {
             return new \Phalcon\Flash\Direct(array('error' => 'alert alert-error', 'success' => 'alert alert-success', 'notice' => 'alert alert-info'));
         });
         $di->set('db', function () use($config) {
             if (isset($config->database->adapter)) {
                 $adapter = $config->database->adapter;
             } else {
                 $adapter = 'Mysql';
             }
             if (is_object($config->database)) {
                 $configArray = $config->database->toArray();
             } else {
                 $configArray = $config->database;
             }
             $className = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter;
             unset($configArray['adapter']);
             return new $className($configArray);
         });
         self::$di = $di;
         $app = new \Phalcon\Mvc\Application();
         $app->setDi($di);
         echo $app->handle()->getContent();
     } catch (\Phalcon\Exception $e) {
         echo get_class($e), ': ', $e->getMessage(), "<br>";
         echo nl2br($e->getTraceAsString());
     } catch (\PDOException $e) {
         echo get_class($e), ': ', $e->getMessage(), "<br>";
         echo nl2br($e->getTraceAsString());
     }
 }
示例#28
0
  * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
  */
 $di = new \Phalcon\DI\FactoryDefault();
 /**
  * Registering a router
  */
 $di->set('router', function () {
     $router = new \Phalcon\Mvc\Router();
     $router->setDefaultModule("frontend");
     return $router;
 });
 /**
  * The URL component is used to generate all kind of urls in the application
  */
 $di->set('url', function () {
     $url = new \Phalcon\Mvc\Url();
     $url->setBaseUri('/@@name@@/');
     return $url;
 });
 /**
  * Start the session the first time some component request the session service
  */
 $di->set('session', function () {
     $session = new \Phalcon\Session\Adapter\Files();
     $session->start();
     return $session;
 });
 /**
  * Handle the request
  */
 $application = new \Phalcon\Mvc\Application();
<?php

// Tuning components for the module dependencies FrontEnd
// Component URL is used to generate all kinds of addresses in the annex
$di->set('url', function () {
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri($this->_config->application->baseUri);
    return $url;
});
$di->set('WWW', function () {
    $url = new StdClass();
    return $url;
});
// Database connection is created based in the parameters defined in the configuration file
$di->setShared('db', function () {
    return new \Phalcon\Db\Adapter\Pdo\Mysql(["host" => $this->_config->database->host, "username" => $this->_config->database->username, "password" => $this->_config->database->password, "dbname" => $this->_config->database->dbname, "persistent" => $this->_config->database->persistent, "options" => array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES '{$this->_config->database->charset}'", PDO::ATTR_CASE => PDO::CASE_LOWER, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ)]);
});
// Component Session. Starting a Session
$di->setShared('session', function () {
    $session = new Phalcon\Session\Adapter\Memcache(['host' => $this->_config->cache->memcached->host, 'port' => $this->_config->cache->memcached->port, 'lifetime' => $this->_config->cache->lifetime, 'prefix' => $this->_config->cache->prefix, 'persistent' => false]);
    $session->start();
    return $session;
});
示例#30
0
<?php

$url = new Phalcon\Mvc\Url();
//Pass the URI in $_GET["_url"]
$url->setBaseUri('/invo/index.php?_url=/');
//Pass the URI using $_SERVER["REQUEST_URI"]
$url->setBaseUri('/invo/index.php/');