Created
August 20, 2016 14:59
-
-
Save Jurigag/ae626f2ffb276cf23e3056f7a06a5cc3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteRule ^$ public/ [L] | |
RewriteRule (.*) public/$1 [L] | |
</IfModule> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Multiple\Backend\Controllers; | |
use Phalcon\Mvc\Controller; | |
class IndexController extends Controller | |
{ | |
public function indexAction() | |
{ | |
return $this->response->forward('login'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Multiple\Backend\Controllers; | |
use Phalcon\Mvc\Controller; | |
class LoginController extends Controller | |
{ | |
public function indexAction() | |
{ | |
$this->view->disable(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Multiple\Backend\Controllers; | |
use Phalcon\Mvc\Controller; | |
use Multiple\Backend\Models\Products as Products; | |
class ProductsController extends Controller | |
{ | |
public function indexAction() | |
{ | |
$this->view->product = Products::findFirst(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Multiple\Backend\Models; | |
use Phalcon\Mvc\Model; | |
class Products extends Model | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Multiple\Backend; | |
use Phalcon\Loader; | |
use Phalcon\Mvc\View; | |
use Phalcon\Mvc\Dispatcher; | |
use Phalcon\DiInterface; | |
use Phalcon\Db\Adapter\Pdo\Mysql as Database; | |
class Module | |
{ | |
public function registerAutoloaders() | |
{ | |
$loader = new Loader(); | |
$loader->registerNamespaces(array( | |
'Multiple\Backend\Controllers' => '../apps/backend/controllers/', | |
'Multiple\Backend\Models' => '../apps/backend/models/', | |
'Multiple\Backend\Plugins' => '../apps/backend/plugins/', | |
)); | |
$loader->register(); | |
} | |
/** | |
* Register the services here to make them general or register in the ModuleDefinition to make them module-specific | |
*/ | |
public function registerServices(DiInterface $di) | |
{ | |
//Registering a dispatcher | |
$di->set('dispatcher', function() { | |
$dispatcher = new Dispatcher(); | |
$dispatcher->setDefaultNamespace("Multiple\Backend\Controllers\\"); | |
return $dispatcher; | |
}); | |
//Registering the view component | |
$di->set('view', function() { | |
$view = new View(); | |
$view->setViewsDir('../apps/backend/views/'); | |
return $view; | |
}); | |
//Set a different connection in each module | |
$di->set('db', function() { | |
return new Database(array( | |
"host" => "localhost", | |
"username" => "root", | |
"password" => "secret", | |
"dbname" => "invo" | |
)); | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Welcome to Backend!</h1> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Welcome</h1> | |
<?php echo $product->name ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Multiple\Frontend\Controllers; | |
use Phalcon\Exception; | |
use Phalcon\Mvc\Controller; | |
class IndexController extends Controller | |
{ | |
public function indexAction() | |
{ | |
throw new Exception('test'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Multiple\Frontend\Controllers; | |
use Phalcon\Mvc\Controller; | |
class ProductsController extends Controller | |
{ | |
public function indexAction() | |
{ | |
return $this->response->redirect('login'); | |
} | |
public function notFoundAction() | |
{ | |
return $this->response->setContent('test'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Multiple\Frontend\Controllers; | |
use Phalcon\Mvc\Controller; | |
class UsersController extends Controller | |
{ | |
public function indexAction() | |
{ | |
echo '<br>', __METHOD__; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Phalcon\Mvc\Model; | |
class Products extends Model | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Multiple\Frontend; | |
use Acl; | |
use Phalcon\Events\Manager; | |
use Phalcon\Loader; | |
use Phalcon\Mvc\Dispatcher; | |
class Module | |
{ | |
public function registerAutoloaders() | |
{ | |
$loader = new Loader(); | |
$loader->registerNamespaces( | |
[ | |
'Multiple\Frontend\Controllers' => '../apps/frontend/controllers/', | |
'Multiple\Frontend\Models' => '../apps/frontend/models/', | |
] | |
); | |
$loader->register(); | |
} | |
/** | |
* Register the services here to make them general or register in the ModuleDefinition to make them module-specific | |
*/ | |
public function registerServices($di) | |
{ | |
//Registering a dispatcher | |
$di->set( | |
'dispatcher', | |
function () { | |
$dispatcher = new Dispatcher(); | |
$dispatcher->setDefaultNamespace("Multiple\Frontend\Controllers\\"); | |
$eventsManager = new Manager(); | |
$eventsManager->attach( | |
'dispatch:beforeException', | |
function ($event, $dispatcher) { | |
$dispatcher->forward( | |
[ | |
'controller' => 'products', | |
'action' => 'notFound', | |
] | |
); | |
return false; | |
} | |
); | |
$dispatcher->setEventsManager($eventsManager); | |
return $dispatcher; | |
} | |
); | |
//Registering the view component | |
$di->set( | |
'view', | |
function () { | |
$view = new \Phalcon\Mvc\View(); | |
$view->setViewsDir('../apps/frontend/views/'); | |
return $view; | |
} | |
); | |
$di->set( | |
'db', | |
function () { | |
return new Database( | |
[ | |
"host" => "localhost", | |
"username" => "root", | |
"password" => "secret", | |
"dbname" => "invo", | |
] | |
); | |
} | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Welcome</h1> | |
<?php echo $product->name ?> | |
<?php echo $this->url(array('controller' => 'products', 'action' => 'algo')) ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AddDefaultCharset UTF-8 | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L] | |
</IfModule> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ALL); | |
use Phalcon\Loader; | |
use Phalcon\Mvc\Router; | |
use Phalcon\DI\FactoryDefault; | |
use Phalcon\Mvc\Application as BaseApplication; | |
class Application extends BaseApplication | |
{ | |
/** | |
* Register the services here to make them general or register in the ModuleDefinition to make them module-specific | |
*/ | |
protected function registerServices() | |
{ | |
$di = new FactoryDefault(); | |
$loader = new Loader(); | |
/** | |
* We're a registering a set of directories taken from the configuration file | |
*/ | |
$loader->registerDirs( | |
array( | |
__DIR__ . '/../apps/library/' | |
) | |
)->register(); | |
//Registering a router | |
$di->set('router', function(){ | |
$router = new Router(); | |
$router->setDefaultModule("frontend"); | |
$router->add('/:controller/:action', array( | |
'module' => 'frontend', | |
'controller' => 1, | |
'action' => 2, | |
)); | |
$router->add("/login", array( | |
'module' => 'backend', | |
'controller' => 'login', | |
'action' => 'index', | |
)); | |
$router->add("/admin/products/:action", array( | |
'module' => 'backend', | |
'controller' => 'products', | |
'action' => 1, | |
)); | |
$router->add("/products/:action", array( | |
'module' => 'frontend', | |
'controller' => 'products', | |
'action' => 1, | |
)); | |
return $router; | |
}); | |
$this->setDI($di); | |
} | |
public function main() | |
{ | |
$this->registerServices(); | |
//Register the installed modules | |
$this->registerModules(array( | |
'frontend' => array( | |
'className' => 'Multiple\Frontend\Module', | |
'path' => '../apps/frontend/Module.php' | |
), | |
'backend' => array( | |
'className' => 'Multiple\Backend\Module', | |
'path' => '../apps/backend/Module.php' | |
) | |
)); | |
echo $this->handle()->getContent(); | |
} | |
} | |
$application = new Application(); | |
$application->main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment