| #0 | Multiple\Www\Controllers\ProductController->getNomenclatureMember(aerus)
/home/clearair/public_html/apps/www/controllers/ProductController.php (85) <?php
namespace Multiple\Www\Controllers;
use Multiple\Base\Models\BannerSet;
use Multiple\Base\Models\Page;
use Multiple\Base\Models\Product;
use Multiple\Base\Models\Promotion;
use Multiple\Www\Forms\ProductsForm;
use Webolie\Core\Traits\TextAwareTrait;
use Webolie\Core\Traits\NomenclatureAwareTrait;
/**
* Class ProductController
* @package Multiple\Www\Controllers
*/
class ProductController extends ControllerBase
{
use TextAwareTrait, NomenclatureAwareTrait;
/**
*
*/
public function indexAction()
{
// product comparison
//set comparison mode
$compare = $this->request->getQuery('compare', 'string');
$inComparison = false;
if (isset($compare)) {
if ($compare == false) {
$this->session->remove('productToCompare');
} else {
$productsToCompare = explode('-', $this->request->get('compare'));
$products = [];
foreach ($productsToCompare as $productId) {
$productId = (int)$productId;
$prod = Product::getProductById($productId);
if ($prod) {
$products[] = $prod;
}
}
if (count($products) > 0) {
$inComparison = true;
}
}
}
$this->view->showComparePanel = true;
$this->view->promotions = Promotion::getPromotionsArr();
if ($inComparison) {
$this->view->showComparePanel = false;
$this->view->productToCompareRes = $products;
// product characteristics
$this->view->productCharacteristicsNomenclature = $this->getNomenclatureGroupMembers('product-characteristics', 'array');
// $this->view->setLayout("nosubheader");
$this->view->pick('product/compare');
// used for structured data generation
$this->getPageDetails('products');
// set structured data for comparison listing
$this->structuredData->add($this->view->productList, null, 'ProductList');
} else {
$params = $this->dispatcher->getParams();
$slug = str_replace('/' . $this->languages->getActiveLanguage(), '', $this->request->getUri());
$pageDetails = Page::getPageBySlug($slug, $this->languages->getActiveLanguage());
$pageKey = $pageDetails->key;
$formFilters = [];
$entity = new \stdClass();
$brand = null;
$type = null;
if (isset($params['brand'])) {
$pageKey = 'products';
$pageKey = $params['brand'] . '-' . $pageKey;
$brand = $this->getNomenclatureMember($params['brand']);
$formFilters['brand'] = $brand->nomenclatureId;
$formFilters['block'] = 'brand';
$entity->brandIdVisual = $brand->nomenclatureId;
} elseif (isset($params['type'])) {
$pageKey = 'products';
$pageKey = $params['type'] . '-' . $pageKey;
$type = $this->getNomenclatureMember($params['type']);
$formFilters['type'] = $type->nomenclatureId;
$formFilters['block'] = 'type';
$entity->typeIdVisual = $type->nomenclatureId;
}
if ($this->request->isPost()) {
$postData = $this->request->getPost();
$formFilters = array_merge($formFilters, $this->request->getPost());
foreach ($postData as $key => $value) {
if ($value) {
$formFilters[$key] = $value;
$entity->{$key . 'IdVisual'} = $value;
}
}
}
if ($this->request->isGet()) {
$getData = $this->request->get();
$formFilters = array_merge($formFilters, $this->request->get());
foreach ($getData as $key => $value) {
if ($value) {
$formFilters[$key] = $value;
$entity->{$key . 'IdVisual'} = $value;
}
}
}
if ($pageKey === 'products') {
$formFilters['condition'] = 'new';
} elseif ($pageKey === 'refurbished-products') {
$formFilters['condition'] = 'refurbished';
}
$this->view->products = Product::getProducts('active', $formFilters);
$this->view->characteristics = $this->getNomenclatureGroupMembers('product-characteristics', 'array', false);
$this->view->categories = $this->getNomenclatureGroupMembers('product-category', 'array', false);
$this->getPageDetails($pageKey, 'yes');
$this->view->productForm = new ProductsForm($entity, $formFilters);
// banner
// TODO: see what slides should be here - maybe per brand/type
$bannerSet = new BannerSet();
$banners = $bannerSet->getBannerSet('homepage');
$topSlides = [];
foreach ($banners->getBanner(['status = "active"']) as $banner) {
$topSlides[] = $banner;
}
if ($brand) {
$this->view->brand = $brand->key;
}
$this->view->productTopSlides = $topSlides;
}
}
/**
*
*/
public function detailsAction()
{
$this->view->pick('product/details');
$this->getPageDetails('products', 'yes');
$this->view->characteristics = $this->getNomenclatureGroupMembers('product-characteristics', 'array', false);
$slug = $this->dispatcher->getParam('slug', 'string');
$this->view->product = Product::getProduct($slug);
if (!$this->view->product || $this->view->product->status != 'active') {
$this->response->redirect($this->link->getLink('/products'));
return;
}
$this->view->promotions = Promotion::getPromotionsArr();
// filter characteristics
$this->view->set = $this->getNomenclatureGroupMembers('what-s-in-the-box', 'array');
$this->modifyPageMetaData($this->view->pageDetails, $this->view->product->getTranslatedResource());
$this->modifyPageHeader($this->view->pageDetails, $this->view->product);
$this->view->rentBenefit = $this->getText('short-rent-benefits');
$this->view->cleancel = $this->getText('filter-tech-cleancel');
$this->view->prefilter = $this->getText('filter-tech-prefilter');
$this->view->carbon = $this->getText('filter-tech-carbon');
$this->view->truehepa = $this->getText('filter-tech-truehepa');
$this->view->plasmawave = $this->getText('filter-tech-plasmawave');
$this->assets->addCss('/frontend/css/magnific-popup.min.css');
$this->assets->addJs('/frontend/js/jquery.magnific-popup.min.js', true, false, ['async' => 'true', 'defer' => 'true']);
$this->assets->addJs('/frontend/js/xzoom.min.js', true, false, []);
}
/**
* Set custom meta tags, originating from entity ones
* @param $pageDetails
* @param $entity
*/
public function modifyPageHeader(&$pageDetails, $entity)
{
if ($entity->headerImage) {
$pageDetails->image = $entity->headerImage;
}
}
/**
* Add product for comparison
*/
public function loadProductComparitionAction()
{
$this->view->disable();
if ($this->request->isPost()) {
// check if there are products in comparison list
if ($this->session->has('productToCompare')) {
$compared = $this->session->get('productToCompare');
return json_encode(['result'=> true, 'count'=> count($compared), 'content'=> $this->renderCompareList($compared)]);
}
return json_encode(['result'=> false, 'count'=> 0, 'content'=> '']);
}
}
/**
* Add product for comparison
*/
public function addProductAction()
{
$this->view->disable();
if ($this->request->isPost()) {
$productId = $this->request->getPost('productId');
$compared = [];
// check if there are products in comparison list
if ($this->session->has('productToCompare')) {
$compared = $this->session->get('productToCompare');
if (count($compared) >= 3) {
return json_encode(['result'=> false, 'count'=> count($compared)+1, 'content'=> $this->translate->_('Limit to compare')]);
}
}
// add current product in the comparison list
if (!in_array($productId, $compared)) {
$compared[] = $productId;
}
// write back the comparison list to session
$this->session->set('productToCompare', $compared);
return json_encode(['result'=> true, 'count'=> count($compared), 'content'=> $this->renderCompareList($compared)]);
}
}
/**
* Remove product from comparison
*/
public function removeProductAction()
{
$this->view->disable();
if ($this->request->isPost()) {
$productId = $this->request->getPost('productId');
$compared = [];
if ($this->session->has('productToCompare')) {
$compared = $this->session->get('productToCompare');
if (($key = array_search($productId, $compared)) !== false) {
unset($compared[$key]);
}
$this->session->set('productToCompare', $compared);
}
if (count($compared)) {
return json_encode(['result'=> true, 'count'=> count($compared), 'content'=> $this->renderCompareList($compared)]);
} else {
$this->session->remove('productToCompare');
}
return json_encode(['result'=> true, 'count'=> 0, 'content'=> '']);
}
}
/**
* Compare Selected products
*/
public function compareSelectedAction()
{
$this->view->disable();
if ($this->session->has('productToCompare')) {
$compared = $this->session->get('productToCompare');
$compareUrl = $this->link->getLink('/products');
$compareUrl .= '?compare=' . implode('-', $compared);
return json_encode(['result' => true, 'content' => $compareUrl]);
// Getting a response instance
// $response = new \Phalcon\Http\Response();
// $this->response->redirect($compareUrl);
// return;
// foreach($compared as $product) {
// $productResToAdd = Product::getProductById($product, $this->languages->getActiveLanguage());
// $productToAdd = $productResToAdd->getProduct();
// }
}
return json_encode(['result' => false, 'content' => $this->link->getLink('/products')]);
}
/**
* Remove all products from comparison
*/
public function removeAllAction()
{
$this->view->disable();
if ($this->request->isPost()) {
$this->session->remove('productToCompare');
return json_encode(['result'=> true, 'count'=> 0, 'content'=> '']);
}
}
/**
* @param $compared
* @return string
*/
private function renderCompareList($compared)
{
$compareProductStr = '';
// TODO: loop on compared products and add them in the return string
foreach ($compared as $product) {
$productResToAdd = Product::getProductById($product, $this->languages->getActiveLanguage());
$productToAdd = $productResToAdd->getProduct();
$productImages = $productToAdd->getImage();
$compareProductStr .= '<div class="col-md-4">';
$compareProductStr .= '<div class="row">';
$compareProductStr .= '<div class="col-5 vertical-center">';
if (!empty($productImages)) {
$compareProductStr .= '<img class="img-fluid" src="' . $productImages[0]->filename . '">';
}
$compareProductStr .= '</div>';
$compareProductStr .= '<div class="col-7 vertical-center justify-mobile">';
$compareProductStr .= '<span class="pull-left">' . $productResToAdd->title . '</span>';
$compareProductStr .= ' <a href="javascript:;" onclick="removeCompared(' . $productToAdd->productId .')" class="pull-right remove-product-from-compare">';
$compareProductStr .= '<span class="remove">X</span>';
$compareProductStr .= '</a>';
$compareProductStr .= '</div>';
$compareProductStr .= '</div>';
$compareProductStr .= '</div>';
}
return $compareProductStr;
}
/**
*
*/
public function promotionsAction()
{
$this->getPageDetails('promotions', '');
$this->view->promotions = Promotion::getPromotionsArr();
$this->view->products = Promotion::getProductsInPromotions();
$this->view->characteristics = $this->getNomenclatureGroupMembers('product-characteristics', 'array', false);
$this->view->categories = $this->getNomenclatureGroupMembers('product-category', 'array', false);
}
}
|
| #4 | Phalcon\Mvc\Application->handle(/bg/aerus-products)
/home/clearair/public_html/public/index.php (119) <?php
/**
* App env start
*/
$appEnv = 'dev';
if (isset($_SERVER['APPLICATION_ENV'])) {
$appEnv = $_SERVER['APPLICATION_ENV'];
} elseif (getenv('APPLICATION_ENV')) {
$appEnv = getenv(['APPLICATION_ENV']);
} elseif (ini_get('APPLICATION_ENV')) {
$appEnv = ini_get('APPLICATION_ENV');
}
defined('APPLICATION_ENV') || define('APPLICATION_ENV', $appEnv);
$appEnv == "production" ? "production" : "preproduction";
if ($appEnv == 'production') {
ini_set('display_errors', 'off');
ini_set('display_startup_errors', 'off');
} else {
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(E_ALL);
// Use Phalcon debug mechanism
$debug = new \Phalcon\Debug();
$debug->listen();
}
/**
* App env end;
*/
require "../config/helpers.php";
if (is_file("../config/config.php")) {
require "../config/config.php";
}
if (is_file("../config/language.php")) {
require "../config/language.php";
} else {
// fallback
$languageSettings = [
'defaultLanguage' => 'en',
'languages' => ['active' => ['en']],
'domainLanguages' => [$_SERVER['SERVER_NAME'] => ['active' => ['en']]],
];
}
if (is_file("../vendor/autoload.php")) {
require "../vendor/autoload.php";
}
use Phalcon\Dispatcher\Exception;
use Phalcon\Mvc\Dispatcher;
/**
* Class Application
*/
class Application extends \Phalcon\Mvc\Application
{
protected $environment;
protected $globalSettings;
protected $languageSettings;
protected $services;
/**
* Application constructor.
* Additional settings may be added to constructor, included at the top of this file and added to initial call
* Example of usage of such settings may be seein in base/config/services.php, commented lines about customSettings
* @param array $settings
*/
public function __construct($environment, $settings = [], $languageSettings = [])
{
$this->environment = $environment;
$this->globalSettings = array_merge($settings, $languageSettings);
}
public function main()
{
$this->_registerServices();
//Register the installed modules
$this->registerModules(
array(
'www' => array(
'className' => 'Multiple\Www\Module',
'path' => '../apps/www/Module.php',
'name' => 'WWW'
),
'admin' => array(
'className' => 'Multiple\Admin\Module',
'path' => '../apps/admin/Module.php',
'name' => 'Admin'
),
'base' => array(
'className' => 'Multiple\Base\Module',
'path' => '../apps/base/Module.php',
'name' => 'Base'
),
'client' => array(
'className' => 'Multiple\Client\Module',
'path' => '../apps/client/Module.php',
'name' => 'Client'
),
'api' => array(
'className' => 'Multiple\Api\Module',
'path' => '../apps/api/Module.php',
'name' => 'Api'
)
)
);
try {
echo $this->handle($this->request->getURI())->getContent();
} catch (\Exception $e) {
if ($this->environment != 'production') {
dd($e);
}
}
}
/**
* Register the services here to make them general
*/
protected function _registerServices()
{
$di = new \Phalcon\DI\FactoryDefault();
$loader = new \Phalcon\Loader();
/**
* We're registering a set of directories
*/
$loader->registerDirs(
array(
__DIR__ . '/../core/service',
__DIR__ . '/../core/facade',
__DIR__ . '/../core/entity',
__DIR__ . '/../vendor',
)
)->register();
$loader->registerNamespaces(
array(
'Decorators' => '../apps/library/decorators/',
'Entity' => '../core/entity/',
'Core\Facade' => '../core/facade/',
'Core\Service' => '../core/service/',
'Core\Helper' => '../core/helper/',
'Multiple\Base\Models' => '../apps/base/models/',
)
);
$loader->register();
require '../apps/base/config/services.php';
//Registering a router
$di->set(
'router',
function () use ($di) {
$router = new \Phalcon\Mvc\Router();
$router->removeExtraSlashes(true);
/*Import module specific routes*/
// get active languages
foreach ($di['config']['languages']['active'] as $lang) {
if (file_exists('../apps/www/config/routes.' . $lang . '.php')) {
require '../apps/www/config/routes.' . $lang . '.php';
}
}
// then get inactive languages
foreach ($di['config']['languages']['inactive'] as $lang) {
if (file_exists('../apps/www/config/routes.' . $lang . '.php')) {
require '../apps/www/config/routes.' . $lang . '.php';
}
}
require '../apps/api/config/routes.php';
require '../apps/admin/config/routes.php';
require '../apps/client/config/routes.php';
return $router;
}
);
//Registering the view component
$di->set(
'view',
function () {
$view = new \Phalcon\Mvc\View();
$view->setViewsDir('../apps/www/views/');
$view->setPartialsDir("partials/");
$view->setLayoutsDir("layouts/");
$view->setLayout("default");
return $view;
}
);
$response = $this->response;
$module = $this->_getModule();
//Registering a dispatcher
$di->set(
'dispatcher',
function () use ($module, $response, $di) {
$dispatcher = new \Phalcon\Mvc\Dispatcher();
//Attach a event listener to the dispatcher
$eventManager = new \Phalcon\Events\Manager();
$activeLanguage = $di['config']['languages'][0];
if (isset($_COOKIE['activeLanguage' . ucfirst($module)]) && $_COOKIE['activeLanguage' . ucfirst($module)]) {
$activeLanguage = $_COOKIE['activeLanguage' . ucfirst($module)];
}
//if($di['config']['env'] == 'production') {
/* $eventManager->attach(
"dispatch:beforeException",
function ($event, $dispatcher, $exception) use ($response, $module, $activeLanguage) {
switch ($exception->getCode()) {
case Exception::EXCEPTION_CYCLIC_ROUTING:
case Exception::EXCEPTION_HANDLER_NOT_FOUND:
case Exception::EXCEPTION_INVALID_HANDLER:
case Exception::EXCEPTION_ACTION_NOT_FOUND:
$response->redirect('../' . $activeLanguage . '/error/404');
return false;
break;
default:
$response->redirect('../' . $activeLanguage . '/error/404');
return false;
break;
}
}
);*/
//}
$dispatcher->setEventsManager($eventManager);
$dispatcher->setDefaultNamespace("Multiple\Www\Controllers\\");
return $dispatcher;
}
);
$this->setDI($di);
}
/**
* @return mixed
*/
private function _getModule()
{
$module = '';
if (isset($this->request->getQuery()['_url'])) {
$module = explode('/', $this->request->getQuery()['_url']);
}
return isset($module[1]) && $module[1] != 'error' ? $module[1] : 'www';
}
/**
* Does a HMVC request inside the application
*
* Inside a controller we might do
* <code>
* $this->app->request([ 'controller' => 'do', 'action' => 'something' ], 'param');
* </code>
*
* @param array $location Array with the route information: 'namespace', 'module', 'controller', 'action', 'params'
* @return mixed
*/
public function request(array $location)
{
/** @var \Phalcon\Mvc\Dispatcher $dispatcher */
$dispatcher = clone $this->di->get('dispatcher');
if (isset($location['module'])) {
$dispatcher->setModuleName($location['module']);
}
if (isset($location['namespace'])) {
$dispatcher->setNamespaceName($location['namespace']);
}
if (!isset($location['controller'])) {
$location['controller'] = 'index';
}
if (!isset($location['action'])) {
$location['action'] = 'index';
}
if (!isset($location['params'])) {
$location['params'] = [];
}
$dispatcher->setControllerName($location['controller']);
$dispatcher->setActionName($location['action']);
$dispatcher->setParams((array)$location['params']);
$dispatcher->dispatch();
$response = $dispatcher->getReturnedValue();
if ($response instanceof ResponseInterface) {
return $response->getContent();
}
return $response;
}
}
//init and load application
// Note: additional settings may be added. See instructions in constructor
$application = new Application($appEnv, $globalSettings, $languageSettings);
$application->main();
|
| #5 | Application->main()
/home/clearair/public_html/public/index.php (321) <?php
/**
* App env start
*/
$appEnv = 'dev';
if (isset($_SERVER['APPLICATION_ENV'])) {
$appEnv = $_SERVER['APPLICATION_ENV'];
} elseif (getenv('APPLICATION_ENV')) {
$appEnv = getenv(['APPLICATION_ENV']);
} elseif (ini_get('APPLICATION_ENV')) {
$appEnv = ini_get('APPLICATION_ENV');
}
defined('APPLICATION_ENV') || define('APPLICATION_ENV', $appEnv);
$appEnv == "production" ? "production" : "preproduction";
if ($appEnv == 'production') {
ini_set('display_errors', 'off');
ini_set('display_startup_errors', 'off');
} else {
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(E_ALL);
// Use Phalcon debug mechanism
$debug = new \Phalcon\Debug();
$debug->listen();
}
/**
* App env end;
*/
require "../config/helpers.php";
if (is_file("../config/config.php")) {
require "../config/config.php";
}
if (is_file("../config/language.php")) {
require "../config/language.php";
} else {
// fallback
$languageSettings = [
'defaultLanguage' => 'en',
'languages' => ['active' => ['en']],
'domainLanguages' => [$_SERVER['SERVER_NAME'] => ['active' => ['en']]],
];
}
if (is_file("../vendor/autoload.php")) {
require "../vendor/autoload.php";
}
use Phalcon\Dispatcher\Exception;
use Phalcon\Mvc\Dispatcher;
/**
* Class Application
*/
class Application extends \Phalcon\Mvc\Application
{
protected $environment;
protected $globalSettings;
protected $languageSettings;
protected $services;
/**
* Application constructor.
* Additional settings may be added to constructor, included at the top of this file and added to initial call
* Example of usage of such settings may be seein in base/config/services.php, commented lines about customSettings
* @param array $settings
*/
public function __construct($environment, $settings = [], $languageSettings = [])
{
$this->environment = $environment;
$this->globalSettings = array_merge($settings, $languageSettings);
}
public function main()
{
$this->_registerServices();
//Register the installed modules
$this->registerModules(
array(
'www' => array(
'className' => 'Multiple\Www\Module',
'path' => '../apps/www/Module.php',
'name' => 'WWW'
),
'admin' => array(
'className' => 'Multiple\Admin\Module',
'path' => '../apps/admin/Module.php',
'name' => 'Admin'
),
'base' => array(
'className' => 'Multiple\Base\Module',
'path' => '../apps/base/Module.php',
'name' => 'Base'
),
'client' => array(
'className' => 'Multiple\Client\Module',
'path' => '../apps/client/Module.php',
'name' => 'Client'
),
'api' => array(
'className' => 'Multiple\Api\Module',
'path' => '../apps/api/Module.php',
'name' => 'Api'
)
)
);
try {
echo $this->handle($this->request->getURI())->getContent();
} catch (\Exception $e) {
if ($this->environment != 'production') {
dd($e);
}
}
}
/**
* Register the services here to make them general
*/
protected function _registerServices()
{
$di = new \Phalcon\DI\FactoryDefault();
$loader = new \Phalcon\Loader();
/**
* We're registering a set of directories
*/
$loader->registerDirs(
array(
__DIR__ . '/../core/service',
__DIR__ . '/../core/facade',
__DIR__ . '/../core/entity',
__DIR__ . '/../vendor',
)
)->register();
$loader->registerNamespaces(
array(
'Decorators' => '../apps/library/decorators/',
'Entity' => '../core/entity/',
'Core\Facade' => '../core/facade/',
'Core\Service' => '../core/service/',
'Core\Helper' => '../core/helper/',
'Multiple\Base\Models' => '../apps/base/models/',
)
);
$loader->register();
require '../apps/base/config/services.php';
//Registering a router
$di->set(
'router',
function () use ($di) {
$router = new \Phalcon\Mvc\Router();
$router->removeExtraSlashes(true);
/*Import module specific routes*/
// get active languages
foreach ($di['config']['languages']['active'] as $lang) {
if (file_exists('../apps/www/config/routes.' . $lang . '.php')) {
require '../apps/www/config/routes.' . $lang . '.php';
}
}
// then get inactive languages
foreach ($di['config']['languages']['inactive'] as $lang) {
if (file_exists('../apps/www/config/routes.' . $lang . '.php')) {
require '../apps/www/config/routes.' . $lang . '.php';
}
}
require '../apps/api/config/routes.php';
require '../apps/admin/config/routes.php';
require '../apps/client/config/routes.php';
return $router;
}
);
//Registering the view component
$di->set(
'view',
function () {
$view = new \Phalcon\Mvc\View();
$view->setViewsDir('../apps/www/views/');
$view->setPartialsDir("partials/");
$view->setLayoutsDir("layouts/");
$view->setLayout("default");
return $view;
}
);
$response = $this->response;
$module = $this->_getModule();
//Registering a dispatcher
$di->set(
'dispatcher',
function () use ($module, $response, $di) {
$dispatcher = new \Phalcon\Mvc\Dispatcher();
//Attach a event listener to the dispatcher
$eventManager = new \Phalcon\Events\Manager();
$activeLanguage = $di['config']['languages'][0];
if (isset($_COOKIE['activeLanguage' . ucfirst($module)]) && $_COOKIE['activeLanguage' . ucfirst($module)]) {
$activeLanguage = $_COOKIE['activeLanguage' . ucfirst($module)];
}
//if($di['config']['env'] == 'production') {
/* $eventManager->attach(
"dispatch:beforeException",
function ($event, $dispatcher, $exception) use ($response, $module, $activeLanguage) {
switch ($exception->getCode()) {
case Exception::EXCEPTION_CYCLIC_ROUTING:
case Exception::EXCEPTION_HANDLER_NOT_FOUND:
case Exception::EXCEPTION_INVALID_HANDLER:
case Exception::EXCEPTION_ACTION_NOT_FOUND:
$response->redirect('../' . $activeLanguage . '/error/404');
return false;
break;
default:
$response->redirect('../' . $activeLanguage . '/error/404');
return false;
break;
}
}
);*/
//}
$dispatcher->setEventsManager($eventManager);
$dispatcher->setDefaultNamespace("Multiple\Www\Controllers\\");
return $dispatcher;
}
);
$this->setDI($di);
}
/**
* @return mixed
*/
private function _getModule()
{
$module = '';
if (isset($this->request->getQuery()['_url'])) {
$module = explode('/', $this->request->getQuery()['_url']);
}
return isset($module[1]) && $module[1] != 'error' ? $module[1] : 'www';
}
/**
* Does a HMVC request inside the application
*
* Inside a controller we might do
* <code>
* $this->app->request([ 'controller' => 'do', 'action' => 'something' ], 'param');
* </code>
*
* @param array $location Array with the route information: 'namespace', 'module', 'controller', 'action', 'params'
* @return mixed
*/
public function request(array $location)
{
/** @var \Phalcon\Mvc\Dispatcher $dispatcher */
$dispatcher = clone $this->di->get('dispatcher');
if (isset($location['module'])) {
$dispatcher->setModuleName($location['module']);
}
if (isset($location['namespace'])) {
$dispatcher->setNamespaceName($location['namespace']);
}
if (!isset($location['controller'])) {
$location['controller'] = 'index';
}
if (!isset($location['action'])) {
$location['action'] = 'index';
}
if (!isset($location['params'])) {
$location['params'] = [];
}
$dispatcher->setControllerName($location['controller']);
$dispatcher->setActionName($location['action']);
$dispatcher->setParams((array)$location['params']);
$dispatcher->dispatch();
$response = $dispatcher->getReturnedValue();
if ($response instanceof ResponseInterface) {
return $response->getContent();
}
return $response;
}
}
//init and load application
// Note: additional settings may be added. See instructions in constructor
$application = new Application($appEnv, $globalSettings, $languageSettings);
$application->main();
|