File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,9 @@ function main() {
165
165
$ router ->addRoute ( // URL: /news/delete
166
166
"#^/news/delete/?$# " , "News \\Delete " , "News \\DeleteHtml "
167
167
);
168
+ $ router ->addRoute ( // URL: /packet/:id.json
169
+ "#^/packet/(\d+)/?.*\.json$# " , "Packet \\View " , "Packet \\ViewJSON "
170
+ );
168
171
$ router ->addRoute ( // URL: /packet/:id.txt
169
172
"#^/packet/(\d+)\.txt# " , "Packet \\View " , "Packet \\ViewPlain "
170
173
);
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace BNETDocs \Views \Packet ;
4
+
5
+ use \BNETDocs \Models \Packet \View as PacketViewModel ;
6
+
7
+ use \CarlBennett \MVC \Libraries \Common ;
8
+ use \CarlBennett \MVC \Libraries \Exceptions \IncorrectModelException ;
9
+ use \CarlBennett \MVC \Libraries \Model ;
10
+ use \CarlBennett \MVC \Libraries \View ;
11
+
12
+ class ViewJSON extends View {
13
+
14
+ public function getMimeType () {
15
+ return 'application/json;charset=utf-8 ' ;
16
+ }
17
+
18
+ public function render ( Model &$ model ) {
19
+ if ( !$ model instanceof PacketViewModel ) {
20
+ throw new IncorrectModelException ();
21
+ }
22
+ echo json_encode ( $ model ->packet , Common::prettyJSONIfBrowser () );
23
+ }
24
+
25
+ }
You can’t perform that action at this time.
0 commit comments