Commit d24b90a9 authored by Ad Schellevis's avatar Ad Schellevis

work in progress new phalcon model code, doesn't interfere with current codebase

parent cc42648f
......@@ -81,3 +81,73 @@ $di->set('session', function () {
$di->set('config', $config);
/**
* Setup router
*/
$di->set('router', function() {
$router = new \Phalcon\Mvc\Router(false);
$router->setDefaultController('index');
$router->setDefaultAction('index');
$router->setDefaultNamespace('OPNsense\Core');
$router->add('/', array(
"controller" => 'index',
"action" => 'index'
));
// probe registered modules and create a namespace map
// for example, OPNsense\Core will be mapped at http(s):\\host\core\..
// module names should be unique in the application, unless you want to overwrite functionality (check glob's sorting).
//
// if the glob for probing the directories turns out to be too slow, we should consider some kind of caching here
//
$registered_modules = array();
$controller_dir = __DIR__."/../controllers/";
foreach (glob($controller_dir."*", GLOB_ONLYDIR) as $namespace_base) {
foreach (glob($namespace_base."/*", GLOB_ONLYDIR) as $module_name) {
if (strpos($module_name, 'OPNsense/Base') === false) {
$namespace_name = str_replace('/', '\\', str_replace($controller_dir, '', $module_name));
$registered_modules[strtolower(basename($module_name))]= $namespace_name;
}
}
}
// add routing for all controllers, using the following convention:
// \module\controller\action\params
// where module is mapped to the corresponding namespace
foreach ($registered_modules as $module_name => $namespace_name) {
$router->add("/".$module_name."/", array(
"namespace" => $namespace_name
));
$router->add("/".$module_name."/:controller/", array(
"namespace" => $namespace_name,
"controller" => 1
));
$router->add("/".$module_name."/:controller/:action/", array(
"namespace" => $namespace_name,
"controller" => 1,
"action" => 2
));
$router->add("/".$module_name."/:controller/:action/:params", array(
"namespace" => $namespace_name,
"controller" => 1,
"action" => 2,
"params" => 3
));
}
$router->handle();
return $router;
});
<?php
namespace OPNsense\unused;
class IndexController extends ControllerBase
{
public function indexAction()
{
}
}
<?php
namespace OPNsense\unused;
namespace OPNsense\Base;
use Phalcon\Mvc\Controller;
class ControllerBase extends Controller
{
/**
* Default action. Set the standard layout.
*/
public function initialize()
{
$this->view->setTemplateBefore('default');
}
}
<?php
namespace OPNsense\Base;
class IndexController extends \OPNsense\Base\ControllerBase
{
public function indexAction()
{
// $this->view->title = $this->request->getURI();
// $this->view->pick('OPNsense/Sample/index');
}
}
<?php
namespace OPNsense\Core;
class IndexController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
$this->view->pick('OPNsense/Core/index');
}
}
<?php
namespace OPNsense\Sample;
class IndexController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
$this->view->title = $this->request->getURI();
$this->view->pick('OPNsense/Sample/index');
}
}
\ No newline at end of file
<?php
namespace OPNsense\Sample;
use Phalcon\Mvc\Controller;
use \OPNsense\Base\ControllerBase;
class PageController extends ControllerBase
{
public function indexAction()
{
$this->view->title = "XXX";
$this->view->pick('OPNsense/Sample/page');
}
public function showAction($postId)
{
$sample = new Sample();
$this->view->title = $sample->title;
$this->view->items = array(array('field_name' =>'test', 'field_content'=>'1234567','field_type'=>"text") );
// Pass the $postId parameter to the view
//$this->view->setVar("postId", $postId);
// $robot = new Sample\Sample();
// $robot->title = 'hoi';
//
// $this->view->title = $postId. "/". $this->persistent->name;
//
$this->view->pick('OPNsense/Sample/page.show');
// $this->flash->error("You don't have permission to access this area");
//
// // Forward flow to another action
// $this->dispatcher->forward(array(
// "controller" => "sample",
// "action" => "index"
// ));
}
}
<?php
namespace OPNsense\Sample;
class Sample
{
public $title = "xx";
}
\ No newline at end of file
Core index
\ No newline at end of file
test sample index page
{{ title }}
{{ partial('layout_partials/footer') }}
show template... {{title|default("??") }}
{% for item in items %}
{{ partial('layout_partials/std_input_field',item) }}
{% endfor %}
<h1>Congratulations!</h1>
<p>You're now flying with Phalcon. Great things are about to happen!</p>
<input type={{field_type}} value="{{field_content}}" name="{{field_name}}" >
<!DOCTYPE html>
<html>
<head>
<title>Phalcon PHP Framework</title>
<title>{{title|default("OPNsense") }}</title>
</head>
<body>
{{ content() }}
{{ content() }}
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment