Replies: 8 comments 6 replies
-
This is absolutely possible. My guess is each app is configured using the document root as a basis, rather than the current directory. For example, maybe you have something like: $base = $_SERVER['DOCUMENT_ROOT']; // This will be the same no matter where you move your project
$autoload = [
'Model'=>$base.'/models';
];
$Loader = new \Phalcon\Loader();
$Loader->registerNamespaces($autoload);
$Loader->register(); instead of: $base = __DIR__; // This will change when you move your project
$autoload = [
'Model'=>$base.'/models';
];
$Loader = new \Phalcon\Loader();
$Loader->registerNamespaces($autoload);
$Loader->register(); |
Beta Was this translation helpful? Give feedback.
-
Thank Dylan for the reply and suggestion. My configuration is below: (BTW: I'm using Phalcon 3.4.5) Config.php file: It's using realpath(dirname(FILE) . '/../..') on the config file. Using out-of-the-box .htaccess files by dev-tools. I received an 404 response. If I tried for example https://demo/demo01/ is not working (404 response), but https://demo/demo01/js/scripts.js is working. Any file on public I can reached except index.php. Apache2 is using a default configuration. For me it's clear that it's related with baseUri or where the App is trying to find the documentRoot I will appreciate any advice. |
Beta Was this translation helpful? Give feedback.
-
Config File: [ 'adapter' => 'Mysql', 'host' => '', //host_db 'username' => '',// user 'password' => '',// password 'dbname' => '', //dbname 'charset' => 'utf8', ], 'application' => [ 'appDir' => APP_PATH . '/', 'controllersDir' => APP_PATH . '/controllers/', 'modelsDir' => APP_PATH . '/models/', 'migrationsDir' => APP_PATH . '/migrations/', 'viewsDir' => APP_PATH . '/views/', 'pluginsDir' => APP_PATH . '/plugins/', 'libraryDir' => APP_PATH . '/library/', 'cacheDir' => BASE_PATH . '/cache/', 'baseUri' => '/', ] ]); Service.php setShared('config', function () { return include APP_PATH . "/config/config.php"; }); /** * The URL component is used to generate all kind of urls in the application */ $di->setShared('url', function () { $config = $this->getConfig(); $url = new UrlResolver(); $url->setBaseUri($config->application->baseUri); return $url; }); /** * Setting up the view component */ $di->setShared('view', function () { $config = $this->getConfig(); $view = new View(); $view->setDI($this); $view->setViewsDir($config->application->viewsDir); $view->registerEngines([ '.volt' => function ($view) { $config = $this->getConfig(); $volt = new VoltEngine($view, $this); $volt->setOptions([ 'compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_' ]); return $volt; }, '.phtml' => PhpEngine::class ]); return $view; }); /** * Database connection is created based in the parameters defined in the configuration file */ $di->setShared('db', function () { $config = $this->getConfig(); $class = 'Phalcon\Db\Adapter\Pdo\\' . $config->database->adapter; $params = [ 'host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname, 'charset' => $config->database->charset ]; if ($config->database->adapter == 'Postgresql') { unset($params['charset']); } $connection = new $class($params); return $connection; }); /** * If the configuration specify the use of metadata adapter use it or use memory otherwise */ $di->setShared('modelsMetadata', function () { return new MetaDataAdapter(); }); /** * Register the session flash service with the Twitter Bootstrap classes */ $di->set('flash', function () { return new Flash([ 'error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning' ]); }); /** * Start the session the first time some component request the session service */ $di->setShared('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); /** * Register router */ $di->setShared('router', function () { $router = new Router(); $router->setUriSource( Router::URI_SOURCE_SERVER_REQUEST_URI ); return $router; }); /* * Error 404 */ $di->set( 'dispatcher', function() use ($di) { $evManager = $di->getShared('eventsManager'); $evManager->attach( "dispatch:beforeException", function($event, $dispatcher, $exception) { switch ($exception->getCode()) { case PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND: case PhDispatcher::EXCEPTION_ACTION_NOT_FOUND: $dispatcher->forward( array( 'controller' => 'error', 'action' => 'show404', ) ); return false; break; default: return false; break; } } ); $dispatcher = new PhDispatcher(); $dispatcher->setEventsManager($evManager); return $dispatcher; }, true ); |
Beta Was this translation helpful? Give feedback.
-
Config.php
Service.php
|
Beta Was this translation helpful? Give feedback.
-
Thanks Dylan. I dettached the $evManager and now I received this: Demo01Controller handler class cannot be loaded
|
Beta Was this translation helpful? Give feedback.
-
I configured in config.php
and nothing changed. It's trying to find the directory name as Controller clearly |
Beta Was this translation helpful? Give feedback.
-
I made the change that you suggested, but continue the same issue. Phalcon is trying to find everything on DocumentRoot. I thought that baseUri will help based on "invo tutorial" for Phalcon 3.4
All my files are the default files created by dev-tools. No changes, except by the evManager. |
Beta Was this translation helpful? Give feedback.
-
Thank Dylan for all your help. I'm using a out-of-the-box dev-tools configuration files and happen the same issue using files outside DocumentRoot |
Beta Was this translation helpful? Give feedback.
-
Hello Gents,
I have some working Phalcon projects and I would like to put all together as Portfolio, so I'm having some issues where Phalcon projects are not working outside the DocumentRoot
DocumentRoot /var/www/demo/
<Directory "/var/www/demo">
Options All
AllowOverride All
Order allow,deny
Allow from all
On DocumentRoot I have many subdirectories like demo01, demo02 with different Phalcon Apps but when I tried to reached it I received an 404 error. If I move each one Phalcon Apps to the DocumentRoot are working well.
(Idea: https://demo/demo01/, https://demo/demo02/ .. )
/
/demo01/
+ app
+ public
+ ..
/demo02/
+ app
+ public
+ ..
/demo03/
..
I added on the .htaccess files a RewriteBase /demo01/ but It's not working. I reviewed the Loglevel debug on my apache server to check the mod_rewrite but I don't see nothing special.
My questions: is it possible to have something like this? I will appreciate your feedback and recommendations.
Thanks
Pablo
Beta Was this translation helpful? Give feedback.
All reactions