本文整理汇总了PHP中Slim::config方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::config方法的具体用法?PHP Slim::config怎么用?PHP Slim::config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim
的用法示例。
在下文中一共展示了Slim::config方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addResult
// Paris and Idiorm
require 'api/Paris/idiorm.php';
require 'api/Paris/paris.php';
require 'api/models/User.php';
require 'api/config.php';
/* Congigurations are set fot ORM
configuration are get from the @Config class.
*/
$con = new Config();
$config = $con->getConfig();
ORM::configure('mysql:host=' . $config["host"] . ';dbname=' . $config["db"]);
ORM::configure('username', $config['username']);
ORM::configure('password', $config['pass']);
/*New App object is created and configure its templates*/
$app = new Slim();
$app->config(array('templates.path' => '.'));
/*App post and get methods.
In get method inde.html is render.
In post method data is saved to database and response is preapred.
*/
$app->post('/addresult', 'addResult');
$app->get('/', function () use($app) {
$app->render('index.html');
});
$app->run();
/*This method is called when client post the data to server
Then request object is got and json body is parsed.
*/
function addResult()
{
$request = Slim::getInstance()->request();
示例2: recall_template
/* == *
*
* SLIM INIT
*
* ==============================================*/
$app = new Slim(array('mode' => 'dev', 'templates.path' => 'templates', 'view' => $index_view, 'cookies.secret_key' => 'r+hhiXlmC4NvsQpq/jaZPK6h+sornz0LC3cbdJNj', 'cookies.cipher' => MCRYPT_RIJNDAEL_256, 'cookies.cipher_mode' => MCRYPT_MODE_CBC, 'cookies.secure' => false));
// set name
//$app->setName('reviewApp');
// End SLIM INIT
/* == *
*
* CONFIGS
*
* ==============================================*/
$app->configureMode('prod', function () use($app) {
$app->config(array('log.enable' => true, 'log.path' => '../logs', 'debug' => false));
});
$app->configureMode('dev', function () use($app) {
$app->config(array('log.enable' => false, 'debug' => true));
});
// End CONFIGS
/* == *
*
* UTILS
*
* ==============================================*/
// recall template
function recall_template()
{
$template_path = $app->config('templates.path');
//returns "../templates"
示例3: testBatchSetSettings
/**
* Test batch set settings
*/
public function testBatchSetSettings()
{
$s = new Slim();
$this->assertEquals('./templates', $s->config('templates.path'));
$this->assertTrue($s->config('debug'));
$s->config(array('templates.path' => './tmpl', 'debug' => false));
$this->assertEquals('./tmpl', $s->config('templates.path'));
$this->assertFalse($s->config('debug'));
}
示例4: Slim
<?php
/**
* Required necessary files
*/
ini_set('display_errors', true);
error_reporting(E_ALL);
require 'Slim/Slim.php';
require 'lib/Textpress.php';
require 'lib/View.php';
/**
* Require config file
* @return Array config values
*/
$config = (require 'config/config.php');
/**
* Create an instance of Slim with custom view
* and set the configurations from config file
*/
$app = new Slim(array('view' => 'View', 'mode' => 'development'));
$app->config($config);
/**
* Create an object of Textpress and pass the object of Slim to it.
*/
$textpress = new Textpress($app);
/**
* Finally run Textpress
*/
$textpress->run();
示例5: Slim
<?php
require 'Slim/Slim.php';
$app = new Slim();
$app->config("mode", "production");
$app->get('/say/hello/:name', function ($name) {
echo "Hello, {$name}!";
});
$app->run();
示例6: dirname
<?php
require_once dirname(__DIR__) . '/bootstrap.php';
require_once PATH_VENDOR_ROOT . '/Slim/Slim.php';
$app = new Slim();
$app->config('templates.path', dirname(__DIR__) . '/templates');
$app->get('/', function () use($app) {
$app->render('index.html', array());
});
$app->get('/mecab', function () use($app) {
$sentence = $app->request()->get('s');
$cl = new ClassLoader();
$ret = $cl->load('Mecab');
$mecab = new Mecab();
/*
$mecab_options = array(
'-u' => PATH_RESOURCE_ROOT . '/word.dic',
);
*/
$ret = $mecab->parseToNode($sentence, $mecab_options);
$app->response()->header('Content-Type', 'application/json; charset=utf-8');
$app->response()->body(json_encode($ret));
});
$app->run();
示例7: getShopDomain
if (empty($selectedLanguage) || !in_array($selectedLanguage, $allowedLanguages)) {
$selectedLanguage = "en";
}
if (isset($_POST["language"]) && in_array($_POST["language"], $allowedLanguages)) {
$selectedLanguage = $_POST["language"];
$_SESSION["language"] = $selectedLanguage;
} elseif (isset($_SESSION["language"]) && in_array($_SESSION["language"], $allowedLanguages)) {
$selectedLanguage = $_SESSION["language"];
} else {
$_SESSION["language"] = $selectedLanguage;
}
$language = (require dirname(__FILE__) . "/assets/lang/{$selectedLanguage}.php");
// Initiate slim
$app = new Slim();
// Assign components
$app->config('install.requirements', new Shopware_Install_Requirements());
$app->config('install.requirementsPath', new Shopware_Install_Requirements_Path());
$app->config('install.language', $selectedLanguage);
// Save post - parameters
$params = $app->request()->params();
foreach ($params as $key => $value) {
if (strpos($key, "c_") !== false) {
$_SESSION["parameters"][$key] = $value;
}
}
// Initiate database object
$databaseParameters = array("user" => isset($_SESSION["parameters"]["c_database_user"]) ? $_SESSION["parameters"]["c_database_user"] : "", "password" => isset($_SESSION["parameters"]["c_database_user"]) ? $_SESSION["parameters"]["c_database_password"] : "", "host" => isset($_SESSION["parameters"]["c_database_user"]) ? $_SESSION["parameters"]["c_database_host"] : "", "port" => isset($_SESSION["parameters"]["c_database_user"]) ? $_SESSION["parameters"]["c_database_port"] : "", "database" => isset($_SESSION["parameters"]["c_database_user"]) ? $_SESSION["parameters"]["c_database_schema"] : "");
$app->config("install.database.parameters", $databaseParameters);
$app->config('install.database', new Shopware_Install_Database($databaseParameters));
function getShopDomain()
{
示例8: testSlimCongfigurationWithArray
/**
* Test Slim defines multiple settings with array
*
* Pre-conditions:
* You have intiailized a Slim application, and you
* pass an associative array into Slim::config
*
* Post-conditions:
* Multiple settings are set correctly.
*/
public function testSlimCongfigurationWithArray(){
Slim::init();
Slim::config(array(
'one' => 'A',
'two' => 'B',
'three' => 'C'
));
$this->assertEquals(Slim::config('one'), 'A');
$this->assertEquals(Slim::config('two'), 'B');
$this->assertEquals(Slim::config('three'), 'C');
}
示例9: testSlimCongfigurationWithArray
/**
* Test Slim defines multiple settings with array
*
* Pre-conditions:
* Slim app instantiated;
* Batch-define multiple configuration settings with associative array;
*
* Post-conditions:
* Multiple settings are set correctly;
*/
public function testSlimCongfigurationWithArray()
{
$app = new Slim();
$app->config(array('one' => 'A', 'two' => 'B', 'three' => 'C'));
$this->assertEquals('A', $app->config('one'));
$this->assertEquals('B', $app->config('two'));
$this->assertEquals('C', $app->config('three'));
}
示例10: render
/**
* Render a template
*
* Call this method within a GET, POST, PUT, DELETE, NOT FOUND, or ERROR
* callable to render a template whose output is appended to the
* current HTTP response body. How the template is rendered is
* delegated to the current View.
*
* @param string $template The name of the template passed into the View::render method
* @param array $data Associative array of data made available to the View
* @param int $status The HTTP response status code to use (Optional)
* @return void
*/
public static function render($template, $data = array(), $status = null)
{
$templatesPath = Slim::config('templates.path');
//Legacy support
if (is_null($templatesPath)) {
$templatesPath = Slim::config('templates_dir');
}
self::view()->setTemplatesDirectory($templatesPath);
if (!is_null($status)) {
self::response()->status($status);
}
self::view()->appendData($data);
self::view()->display($template);
}
示例11: setLayout
/**
* Set layout file
*/
public function setLayout($layout)
{
$layoutFile = is_bool($layout) ? $this->slim->config('layout.file') . '.php' : $layout . ".php";
$this->slim->view()->setLayout($layoutFile);
}
示例12: authenticate
<?php
require_once 'slim/Slim.php';
require_once 'slim/SmartyView.php';
require_once 'classes/app.php';
$app = new Slim(array('templates.path' => 'templates', 'view' => 'SmartyView', 'log.path' => 'slim/Logs', 'log.level' => 4, 'cookies.secret_key' => "[SALT]", 'mode' => 'development'));
$app->configureMode('production', function () use($app) {
$app->config(array('log.enable' => true, 'debug' => false));
});
$app->configureMode('development', function () use($app) {
$app->config(array('log.enable' => true, 'debug' => true));
});
//# Set your API_Key and Client secret #//
//# Available here: https://eventbrite.com/api/key #//
$app->config('api_key', 'YOUR_API_KEY_HERE');
$app->config('client_secret', 'YOUR_CLIENT_SECRET_HERE');
function authenticate()
{
$app = Slim::getInstance();
if (!App::user()) {
$app->redirect("/connect/");
}
}
//## ROUTES ##//
$app->get('/', function () use($app) {
$params = App::start();
$params['title'] = "Home";
$params['page'] = "home";
if (!App::user()) {
$params['button'] = "Connect";
} else {
示例13: dirname
<?php
define('__ROOT__', dirname(__FILE__));
require_once 'models/db.php';
require_once 'shared/Slim/Slim.php';
require_once 'shared/Slim/Views/TwigView.php';
TwigView::$twigDirectory = __DIR__ . '/shared/Slim/Views/Twig';
$app = new Slim(array('view' => new TwigView()));
$app->config(array('debug' => true, 'templates.path' => 'views'));
require_once 'controllers/home.php';
$app->run();
示例14: Slim
<?php
// Initialize flags, config, models, cache, etc.
require_once 'init.php';
require_once BASE_DIR . '/vendor/Slim/Slim/Slim.php';
require_once BASE_DIR . '/vendor/Slim-Extras/Log Writers/TimestampLogFileWriter.php';
$app = new Slim(array('mode' => defined('PRODUCTION') ? 'production' : 'development', 'debug' => false, 'log.enabled' => true, 'log.writer' => new TimestampLogFileWriter(array('path' => BASE_DIR, 'name_format' => '\\s\\l\\i\\m\\_\\l\\o\\g'))));
$app->configureMode('development', function () use($app) {
$app->config(array('debug' => true));
});
$app->configureMode('production', function () use($app) {
error_reporting(0);
$app->notFound(function () use($app) {
$page = new ErrorController(404);
$page->render();
});
$app->error(function (Exception $e) use($app) {
$app->response()->status(500);
if (!$app->request()->isAjax()) {
$page = new ErrorController(500);
$page->render();
}
$app->stop();
if (file_exists(BASE_DIR . '/.gbemail')) {
foreach (explode('\\n', file_get_contents(BASE_DIR . '/.gbemail')) as $email) {
mail(trim($email), "GetchaBooks Error", get_error_message($e));
}
}
});
});
$app->hook('slim.before', function () use($app) {
示例15: init
/**
* Initialize Slim
*
* This instantiates the Slim application using the provided
* application settings if available.
*
* Legacy Support:
*
* To support applications built with an older version of Slim,
* this method's argument may also be a string (the name of a View class)
* or an instance of a View class or subclass.
*
* @param array|string|Slim_View $viewClass An array of settings;
* The name of a View class;
* A View class or subclass instance;
* @return void
*/
public static function init($userSettings = array())
{
//Legacy support
if (is_string($userSettings) || $userSettings instanceof Slim_View) {
$settings = array('view' => $userSettings);
} else {
$settings = (array) $userSettings;
}
//Init app
self::$app = new Slim($settings);
//Init Not Found and Error handlers
self::notFound(array('Slim', 'defaultNotFound'));
self::error(array('Slim', 'defaultError'));
//Init view
self::view(Slim::config('view'));
//Init logging
if (Slim::config('log.enable') === true) {
$logger = Slim::config('log.logger');
if (empty($logger)) {
Slim_Log::setLogger(new Slim_Logger(Slim::config('log.path'), Slim::config('log.level')));
} else {
Slim_Log::setLogger($logger);
}
}
//Start session if not already started
if (session_id() === '') {
$sessionHandler = Slim::config('session.handler');
if ($sessionHandler instanceof Slim_Session_Handler) {
$sessionHandler->register();
}
session_start();
if (isset($_COOKIE[session_id()])) {
Slim::deleteCookie(session_id());
}
session_regenerate_id(true);
}
//Init flash messaging
self::$app->flash = new Slim_Session_Flash(self::config('session.flash_key'));
self::view()->setData('flash', self::$app->flash);
//Determine mode
if (isset($_ENV['SLIM_MODE'])) {
self::$app->mode = (string) $_ENV['SLIM_MODE'];
} else {
$configMode = Slim::config('mode');
self::$app->mode = $configMode ? (string) $configMode : 'development';
}
}