Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
249de9df
Commit
249de9df
authored
Jan 29, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
work in progress OPNsense frontend mvc framework
parent
1dc13c29
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
114 additions
and
3 deletions
+114
-3
ControllerBase.php
...ense/mvc/app/controllers/OPNsense/Base/ControllerBase.php
+18
-0
PageController.php
...se/mvc/app/controllers/OPNsense/Sample/PageController.php
+42
-1
BaseModel.php
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
+40
-0
ArrayField.php
...se/mvc/app/models/OPNsense/Base/FieldTypes/ArrayField.php
+1
-1
BaseField.php
...nse/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
+1
-0
page.volt
src/opnsense/mvc/app/views/OPNsense/Sample/page.volt
+12
-1
No files found.
src/opnsense/mvc/app/controllers/OPNsense/Base/ControllerBase.php
View file @
249de9df
...
...
@@ -43,4 +43,22 @@ class ControllerBase extends Controller
{
$this
->
view
->
setTemplateBefore
(
'default'
);
}
/**
* @param $dispatcher
*/
public
function
beforeExecuteRoute
(
$dispatcher
)
{
// Execute before every found action
// TODO: implement default behavior
}
/**
* @param $dispatcher
*/
public
function
afterExecuteRoute
(
$dispatcher
)
{
// Executed after every found action
// TODO: implement default behavior
}
}
src/opnsense/mvc/app/controllers/OPNsense/Sample/PageController.php
View file @
249de9df
...
...
@@ -30,6 +30,7 @@ namespace OPNsense\Sample;
use
Phalcon\Mvc\Controller
;
use
\OPNsense\Base\ControllerBase
;
use
\OPNsense\Core\Config
;
/**
* Class PageController
...
...
@@ -37,12 +38,52 @@ use \OPNsense\Base\ControllerBase;
*/
class
PageController
extends
ControllerBase
{
/**
* controller for sample index page, defaults to http://<host>/sample/page
*/
public
function
indexAction
()
{
$this
->
view
->
title
=
"XXX"
;
// load model and send to view, this model is automatically filled with data from the config.xml
$mdlSample
=
new
Sample
();
$this
->
view
->
sample
=
$mdlSample
;
// set title and pick a template
$this
->
view
->
title
=
"test page"
;
$this
->
view
->
pick
(
'OPNsense/Sample/page'
);
}
public
function
saveAction
()
{
// save action should be a post, redirect to index
if
(
$this
->
request
->
isPost
()
==
true
)
{
// create model(s)
$mdlSample
=
new
Sample
();
// Access POST data and save parts to model
foreach
(
$this
->
request
->
getPost
()
as
$key
=>
$value
)
{
$refparts
=
explode
(
"_"
,
$key
);
if
(
array_shift
(
$refparts
)
==
"sample"
)
{
// this post item belongs to the Sample model (prefixed in view)
$mdlSample
->
setNodeByReference
(
implode
(
"."
,
$refparts
),
$value
);
}
}
$mdlSample
->
serializeToConfig
();
$cnf
=
Config
::
getInstance
();
$cnf
->
save
();
// redirect to index
$this
->
dispatcher
->
forward
(
array
(
"action"
=>
"index"
));
}
else
{
// Forward flow to the index action
$this
->
dispatcher
->
forward
(
array
(
"action"
=>
"index"
));
}
}
public
function
showAction
(
$postId
)
{
$sample
=
new
Sample
();
...
...
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
View file @
249de9df
...
...
@@ -338,4 +338,44 @@ abstract class BaseModel
}
$this
->
internalSerializeToConfig
();
}
/**
* find node by reference starting at the root node
* @param BaseField $node source node
* @param string $reference node reference (point separated "node.subnode.subsubnode")
* @return BaseField|null field node by reference (or null if not found)
*/
public
function
getNodeByReference
(
$reference
)
{
$parts
=
explode
(
"."
,
$reference
);
$node
=
$this
->
internalData
;
while
(
count
(
$parts
)
>
0
)
{
$childName
=
array_shift
(
$parts
);
if
(
array_key_exists
(
$childName
,
$node
->
getChildren
()))
{
$node
=
$node
->
getChildren
()[
$childName
];
}
else
{
return
null
;
}
}
return
$node
;
}
/**
* set node value by name (if reference exists)
* @param string $reference node reference (point separated "node.subnode.subsubnode")
* @param string $value
* @return bool value saved yes/no
*/
public
function
setNodeByReference
(
$reference
,
$value
)
{
$node
=
$this
->
getNodeByReference
(
$reference
);
if
(
$node
!=
null
)
{
$node
->
setValue
(
$value
);
return
true
;
}
else
{
return
false
;
}
}
}
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ArrayField.php
View file @
249de9df
...
...
@@ -56,7 +56,7 @@ class ArrayField extends BaseField
}
/**
*
*
copy first node pointer as template node to make sure we always have a template to create new nodes from.
*/
private
function
internalCopyStructure
()
{
...
...
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
View file @
249de9df
...
...
@@ -306,4 +306,5 @@ abstract class BaseField
$this
->
internalIsRequired
=
false
;
}
}
}
src/opnsense/mvc/app/views/OPNsense/Sample/page.volt
View file @
249de9df
test sample -> page
<div>
<i>this is a sample page for the OPNsense mvc frontend framework</i>
</div>
{{ sample.tag1 }}
<form action="save" method="post">
<input type="text" name="sample.{{sample.tag1.__reference}}" value="{{sample.tag1}}"><br>
<input type="text" name="sample.{{sample.tagX.tag1.__reference}}" value="{{sample.tagX.tag1}}"><br>
<input type="submit" value="Submit">
</form>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment