本文整理匯總了PHP中Backend\Core\Engine\Model::getContainer方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model::getContainer方法的具體用法?PHP Model::getContainer怎麽用?PHP Model::getContainer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Backend\Core\Engine\Model
的用法示例。
在下文中一共展示了Model::getContainer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: outputCSV
/**
* Output a CSV-file as a download
*
* @param string $filename The name of the file.
* @param array $array The array to convert.
* @param array $columns The column names you want to use.
* @param array $excludeColumns The columns you want to exclude.
*/
public static function outputCSV($filename, array $array, array $columns = null, array $excludeColumns = null)
{
// get settings
$splitCharacter = Authentication::getUser()->getSetting('csv_split_character');
$lineEnding = Authentication::getUser()->getSetting('csv_line_ending');
// reformat
if ($lineEnding == '\\n') {
$lineEnding = "\n";
}
if ($lineEnding == '\\r\\n') {
$lineEnding = "\r\n";
}
// convert into CSV
$csv = \SpoonFileCSV::arrayToString($array, $columns, $excludeColumns, $splitCharacter, '"', $lineEnding);
// set headers for download
$charset = BackendModel::getContainer()->getParameter('kernel.charset');
$headers[] = 'Content-type: application/csv; charset=' . $charset;
$headers[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
$headers[] = 'Content-Length: ' . strlen($csv);
$headers[] = 'Pragma: no-cache';
// overwrite the headers
\SpoonHTTP::setHeaders($headers);
// output the CSV
echo $csv;
exit;
}
示例2: getContent
/**
* Create the XML based on the locale items.
*/
public function getContent()
{
$charset = BackendModel::getContainer()->getParameter('kernel.charset');
// create XML
$xmlOutput = BackendLocaleModel::createXMLForExport($this->locale);
return new Response($xmlOutput, Response::HTTP_OK, ['Content-Disposition' => 'attachment; filename="locale_' . BackendModel::getUTCDate('d-m-Y') . '.xml"', 'Content-Type' => 'application/octet-stream;charset=' . $charset, 'Content-Length' => '' . mb_strlen($xmlOutput)]);
}
示例3: generateURL
/**
* Generate an url, using the predefined callback.
*
* @param string $url The base-url to start from.
* @param string $class The Fully Qualified Class Name or service name
* @param string $method The method that needs to be called
* @param array $parameters The parameters for the callback
*
* @throws Exception When the function does not exist
*
* @return string
*/
public function generateURL($url, $class, $method, array $parameters = [])
{
// check if the class is a service
if (Model::getContainer()->has($class)) {
$class = Model::getContainer()->get($class);
}
// validate (check if the function exists)
if (!is_callable([$class, $method])) {
throw new Exception('The callback-method doesn\'t exist.');
}
// when using ->getValue() in SpoonFormText fields the function is using htmlentities(),
// so we must decode it again first!
$url = SpoonFilter::htmlentitiesDecode($url);
$actualParameters = [];
// build parameters for use in the callback
$actualParameters[] = Uri::getUrl($url);
// add parameters set by user
if (!empty($parameters)) {
foreach ($parameters as $parameter) {
$actualParameters[] = $parameter;
}
}
// get the real url
return call_user_func_array([$class, $method], $actualParameters);
}
示例4: execute
/**
* Execute the action
*/
public function execute()
{
parent::execute();
$isGod = BackendAuthentication::getUser()->isGod();
// get possible languages
if ($isGod) {
$possibleLanguages = array_unique(array_merge(BL::getWorkingLanguages(), BL::getInterfaceLanguages()));
} else {
$possibleLanguages = BL::getWorkingLanguages();
}
// get parameters
$language = \SpoonFilter::getPostValue('language', array_keys($possibleLanguages), null, 'string');
$module = \SpoonFilter::getPostValue('module', BackendModel::getModules(), null, 'string');
$name = \SpoonFilter::getPostValue('name', null, null, 'string');
$type = \SpoonFilter::getPostValue('type', BackendModel::getContainer()->get('database')->getEnumValues('locale', 'type'), null, 'string');
$application = \SpoonFilter::getPostValue('application', array('Backend', 'Frontend'), null, 'string');
$value = \SpoonFilter::getPostValue('value', null, null, 'string');
// validate values
if (trim($value) == '' || $language == '' || $module == '' || $type == '' || $application == '' || $application == 'Frontend' && $module != 'Core') {
$error = BL::err('InvalidValue');
}
// in case this is a 'act' type, there are special rules concerning possible values
if ($type == 'act' && !isset($error)) {
if (urlencode($value) != CommonUri::getUrl($value)) {
$error = BL::err('InvalidActionValue', $this->getModule());
}
}
// no error?
if (!isset($error)) {
// build item
$item['language'] = $language;
$item['module'] = $module;
$item['name'] = $name;
$item['type'] = $type;
$item['application'] = $application;
$item['value'] = $value;
$item['edited_on'] = BackendModel::getUTCDate();
$item['user_id'] = BackendAuthentication::getUser()->getUserId();
// does the translation exist?
if (BackendLocaleModel::existsByName($name, $type, $module, $language, $application)) {
// add the id to the item
$item['id'] = (int) BackendLocaleModel::getByName($name, $type, $module, $language, $application);
// update in db
BackendLocaleModel::update($item);
} else {
// insert in db
BackendLocaleModel::insert($item);
}
// output OK
$this->output(self::OK);
} else {
$this->output(self::ERROR, null, $error);
}
}
示例5: commentsGet
/**
* Get the comments
*
* @param string $status The type of comments to get. Possible values are: published, moderation, spam.
* @param int $limit The maximum number of items to retrieve.
* @param int $offset The offset.
*
* @return array
*/
public static function commentsGet($status = null, $limit = 30, $offset = 0)
{
// authorize
if (BaseAPI::isAuthorized() && BaseAPI::isValidRequestMethod('GET')) {
// redefine
$limit = (int) $limit;
// validate
if ($limit > 10000) {
return BaseAPI::output(BaseAPI::ERROR, array('message' => 'Limit can\'t be larger than 10000.'));
}
// get comments
$comments = (array) BackendModel::getContainer()->get('database')->getRecords('SELECT i.id, UNIX_TIMESTAMP(i.created_on) AS created_on, i.author, i.email, i.website, i.text, i.type, i.status,
p.id AS post_id, p.title AS post_title, m.url AS post_url, p.language AS post_language
FROM blog_comments AS i
INNER JOIN blog_posts AS p ON i.post_id = p.id AND i.language = p.language
INNER JOIN meta AS m ON p.meta_id = m.id
WHERE p.status = ?
GROUP BY i.id
ORDER BY i.id DESC
LIMIT ?, ?', array('active', (int) $offset, $limit));
$totalCount = (int) BackendModel::getContainer()->get('database')->getVar('SELECT COUNT(i.id)
FROM blog_comments AS i
INNER JOIN blog_posts AS p ON i.post_id = p.id AND i.language = p.language
INNER JOIN meta AS m ON p.meta_id = m.id
WHERE p.status = ?', array('active'));
$return = array('comments' => null, 'total_count' => $totalCount);
// build return array
foreach ($comments as $row) {
// create array
$item['comment'] = array();
// article meta data
$item['comment']['article']['@attributes']['id'] = $row['post_id'];
$item['comment']['article']['@attributes']['lang'] = $row['post_language'];
$item['comment']['article']['title'] = $row['post_title'];
$item['comment']['article']['url'] = SITE_URL . BackendModel::getURLForBlock('Blog', 'Detail', $row['post_language']) . '/' . $row['post_url'];
// set attributes
$item['comment']['@attributes']['id'] = $row['id'];
$item['comment']['@attributes']['created_on'] = date('c', $row['created_on']);
$item['comment']['@attributes']['status'] = $row['status'];
// set content
$item['comment']['text'] = $row['text'];
$item['comment']['url'] = $item['comment']['article']['url'] . '#comment-' . $row['id'];
// author data
$item['comment']['author']['@attributes']['email'] = $row['email'];
$item['comment']['author']['name'] = $row['author'];
$item['comment']['author']['website'] = $row['website'];
// add
$return['comments'][] = $item;
}
return $return;
}
}
示例6: createXML
/**
* Create the XML based on the locale items.
*/
private function createXML()
{
$charset = BackendModel::getContainer()->getParameter('kernel.charset');
// create XML
$xmlOutput = BackendLocaleModel::createXMLForExport($this->locale);
// xml headers
header('Content-Disposition: attachment; filename="locale_' . BackendModel::getUTCDate('d-m-Y') . '.xml"');
header('Content-Type: application/octet-stream;charset=' . $charset);
header('Content-Length: ' . strlen($xmlOutput));
// output XML
echo $xmlOutput;
exit;
}
示例7: outputCSV
/**
* Output a CSV-file as a download
*
* @param string $filename The name of the file.
* @param array $array The array to convert.
* @param array $columns The column names you want to use.
* @param array $excludeColumns The columns you want to exclude.
*/
public static function outputCSV($filename, array $array, array $columns = null, array $excludeColumns = null)
{
// get settings
$splitCharacter = Authentication::getUser()->getSetting('csv_split_character');
$lineEnding = Authentication::getUser()->getSetting('csv_line_ending');
// reformat
if ($lineEnding == '\\n') {
$lineEnding = "\n";
}
if ($lineEnding == '\\r\\n') {
$lineEnding = "\r\n";
}
// convert into CSV
$csv = \SpoonFileCSV::arrayToString($array, $columns, $excludeColumns, $splitCharacter, '"', $lineEnding);
// set headers for download
$charset = BackendModel::getContainer()->getParameter('kernel.charset');
throw new RedirectException('Return the csv data', new Response($csv, Response::HTTP_OK, ['Content-type' => 'application/csv; charset=' . $charset, 'Content-Disposition' => 'attachment; filename="' . $filename . '"', 'Content-Length' => mb_strlen($csv), 'Pragma' => 'no-cache']));
}
示例8: __construct
/**
* @param string $name Name of the form.
* @param string $action The action (URL) whereto the form will be submitted, if not provided it
* will be autogenerated.
* @param string $method The method to use when submitting the form, default is POST.
* @param bool $useToken Should we automagically add a formtoken?
* @param bool $useGlobalError Should we automagically show a global error?
*/
public function __construct($name = null, $action = null, $method = 'post', $useToken = true, $useGlobalError = true)
{
if (BackendModel::getContainer()->has('url')) {
$this->URL = BackendModel::getContainer()->get('url');
}
if (BackendModel::getContainer()->has('header')) {
$this->header = BackendModel::getContainer()->get('header');
}
$this->useGlobalError = (bool) $useGlobalError;
// build a name if there wasn't one provided
$name = $name === null ? \SpoonFilter::toCamelCase($this->URL->getModule() . '_' . $this->URL->getAction(), '_', true) : (string) $name;
// build the action if it wasn't provided
$action = $action === null ? '/' . $this->URL->getQueryString() : (string) $action;
// call the real form-class
parent::__construct($name, $action, $method, $useToken);
// add default classes
$this->setParameter('id', $name);
$this->setParameter('class', 'forkForms submitWithLink');
}
示例9: execute
/**
* Execute the actions
*/
public function execute()
{
parent::execute();
//--Get all the addresses
$addresses = BackendAddressesModel::getAllAddresses(1);
foreach ($addresses as &$address) {
$address = BackendAddressesModel::get($address['id']);
foreach ($address as &$row) {
$row = $row == "" ? "-" : $row;
}
}
foreach ($addresses as $address) {
set_time_limit(10);
if (filter_var($address['email'], FILTER_VALIDATE_EMAIL) && $address['send_mail'] == 0) {
//--Send mail for the address
BackendMailer::addEmail("Nieuwe website Namev.be met uw eigen bedrijfs-pagina", BACKEND_MODULE_PATH . '/layout/templates/mails/send_email.tpl', $address, 'waldo@comsa.be', $address['company']);
// BackendMailer::addEmail("Nieuwe website Namev.be met uw eigen bedrijfs-pagina", BACKEND_MODULE_PATH . '/layout/templates/mails/send_email.tpl', $address, 'info@namev.be', $address['company']);
// BackendMailer::addEmail("Nieuwe website Namev.be met uw eigen bedrijfs-pagina", BACKEND_MODULE_PATH . '/layout/templates/mails/send_email.tpl', $address, $address['email'], $address['company']);
BackendModel::getContainer()->get('database')->update('addresses', array("send_mail" => 1), 'id = ?', (int) $address['id']);
die;
}
}
//--Update the address row when e-mail is send
}
示例10: getStatistics
/**
* Get some statistics about the compression, like the Weissman score™
*
* @return array Compression statistics
*/
public static function getStatistics()
{
$db = BackendModel::getContainer()->get('database');
return $db->getRecord('SELECT COUNT(i.id) AS total_compressed, SUM(i.saved_bytes) AS saved_bytes,
concat(round(( 100 - (SUM(compressed_size) / SUM(original_size) * 100)),2),"%") AS saved_percentage
FROM compression_history AS i');
}
示例11: handleCategory
/**
* Handle the category of a post
*
* We'll check if the category exists in the fork blog module, and create it if it doesn't.
*
* @param string $category The post category
* @return int
*/
private function handleCategory($category = '')
{
// Does a category with this name exist?
/* @var \SpoonDatabase $db */
$db = BackendModel::getContainer()->get('database');
$id = (int) $db->getVar('SELECT id FROM blog_categories WHERE title=? AND language=?', array($category, BL::getWorkingLanguage()));
// We found an id!
if ($id > 0) {
return $id;
}
// Return default if we got an empty string
if (trim($category) == '') {
return 2;
}
// We should create a new category
$cat = array();
$cat['language'] = BL::getWorkingLanguage();
$cat['title'] = $category;
$meta = array();
$meta['keywords'] = $category;
$meta['description'] = $category;
$meta['title'] = $category;
$meta['url'] = $category;
return Model::insertCategory($cat, $meta);
}
示例12: updateRevision
/**
* Update a page revision without generating a new revision.
* Needed to add an image to a page.
*
* @param $revision_id
* @param $item
*/
public static function updateRevision($revision_id, $item)
{
BackendModel::getContainer()->get('database')->update('blog_posts', $item, 'revision_id = ?', array($revision_id));
}
示例13: getNavigationUrl
/**
* Get the url of a navigation item.
* If the item doesn't have an id, it will search recursively until it finds one.
*
* @param int $id The id to search for.
* @return string
*/
private function getNavigationUrl($id)
{
$id = (int) $id;
// get url
$item = (array) BackendModel::getContainer()->get('database')->getRecord('SELECT id, url FROM backend_navigation WHERE id = ?', array($id));
if (empty($item)) {
return '';
} elseif ($item['url'] != '') {
return $item['url'];
} else {
// get the first child
$childId = (int) BackendModel::getContainer()->get('database')->getVar('SELECT id FROM backend_navigation WHERE parent_id = ? ORDER BY sequence ASC LIMIT 1', array($id));
// get its url
return $this->getNavigationUrl($childId);
}
}
示例14: parseVars
/**
* Parse some vars
*/
private function parseVars()
{
// assign a placeholder var
$this->assign('var', '');
// assign current timestamp
$this->assign('timestamp', time());
// check on url object
if (Model::getContainer()->has('url')) {
$url = Model::get('url');
if ($url instanceof Url) {
$this->assign('bodyID', \SpoonFilter::toCamelCase($url->getModule(), '_', true));
// build classes
$bodyClass = \SpoonFilter::toCamelCase($url->getModule() . '_' . $url->getAction(), '_', true);
// special occasions
if ($url->getAction() == 'add' || $url->getAction() == 'edit') {
$bodyClass = $url->getModule() . 'AddEdit';
}
// assign
$this->assign('bodyClass', $bodyClass);
}
}
if (Model::has('navigation')) {
$navigation = Model::get('navigation');
if ($navigation instanceof Navigation) {
$navigation->parse($this);
}
}
foreach ($this->forms as $form) {
if ($form->isSubmitted() && !$form->isCorrect()) {
$this->assign('form_error', true);
break;
}
}
$this->assign('cookies', Model::get('request')->cookies->all());
}
示例15: processQueryString
/**
* Process the querystring
*/
private function processQueryString()
{
// store the querystring local, so we don't alter it.
$queryString = $this->getQueryString();
// find the position of ? (which separates real URL and GET-parameters)
$positionQuestionMark = mb_strpos($queryString, '?');
// separate the GET-chunk from the parameters
$getParameters = '';
if ($positionQuestionMark === false) {
$processedQueryString = $queryString;
} else {
$processedQueryString = mb_substr($queryString, 0, $positionQuestionMark);
$getParameters = mb_substr($queryString, $positionQuestionMark);
}
// split into chunks, a Backend URL will always look like /<lang>/<module>/<action>(?GET)
$chunks = (array) explode('/', trim($processedQueryString, '/'));
// check if this is a request for a AJAX-file
$isAJAX = isset($chunks[1]) && $chunks[1] == 'ajax';
// get the language, this will always be in front
$language = '';
if (isset($chunks[1]) && $chunks[1] != '') {
$language = \SpoonFilter::getValue($chunks[1], array_keys(BackendLanguage::getWorkingLanguages()), '');
}
// no language provided?
if ($language == '' && !$isAJAX) {
// remove first element
array_shift($chunks);
// redirect to login
$this->redirect('/' . NAMED_APPLICATION . '/' . SITE_DEFAULT_LANGUAGE . (empty($chunks) ? '' : '/') . implode('/', $chunks) . $getParameters);
}
// get the module, null will be the default
$module = isset($chunks[2]) && $chunks[2] != '' ? $chunks[2] : 'Dashboard';
$module = \SpoonFilter::toCamelCase($module);
// get the requested action, if it is passed
if (isset($chunks[3]) && $chunks[3] != '') {
$action = \SpoonFilter::toCamelCase($chunks[3]);
} elseif (!$isAJAX) {
// Check if we can load the config file
$configClass = 'Backend\\Modules\\' . $module . '\\Config';
if ($module == 'Core') {
$configClass = 'Backend\\Core\\Config';
}
try {
// when loading a backend url for a module that doesn't exist, without
// providing an action, a FatalErrorException occurs, because the config
// class we're trying to load doesn't exist. Let's just throw instead,
// and catch it immediately.
if (!class_exists($configClass)) {
throw new Exception('The config class does not exist');
}
/** @var BackendBaseConfig $config */
$config = new $configClass($this->getKernel(), $module);
// set action
$action = $config->getDefaultAction() !== null ? $config->getDefaultAction() : 'Index';
} catch (Exception $ex) {
if (BackendModel::getContainer()->getParameter('kernel.debug')) {
throw new Exception('The config file for the module (' . $module . ') can\'t be found.');
} else {
// @todo don't use redirects for error, we should have something like an invoke method.
// build the url
$errorUrl = '/' . NAMED_APPLICATION . '/' . $language . '/error?type=action-not-allowed';
// add the querystring, it will be processed by the error-handler
$errorUrl .= '&querystring=' . rawurlencode('/' . $this->getQueryString());
// redirect to the error page
$this->redirect($errorUrl, 307);
}
}
}
// AJAX parameters are passed via GET or POST
if ($isAJAX) {
$module = isset($_GET['fork']['module']) ? $_GET['fork']['module'] : '';
$action = isset($_GET['fork']['action']) ? $_GET['fork']['action'] : '';
$language = isset($_GET['fork']['language']) ? $_GET['fork']['language'] : SITE_DEFAULT_LANGUAGE;
$module = isset($_POST['fork']['module']) ? $_POST['fork']['module'] : $module;
$action = isset($_POST['fork']['action']) ? $_POST['fork']['action'] : $action;
$language = isset($_POST['fork']['language']) ? $_POST['fork']['language'] : $language;
$this->setModule($module);
$this->setAction($action);
BackendLanguage::setWorkingLanguage($language);
} else {
$this->processRegularRequest($module, $action, $language);
}
}