Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tina4:basic-routing [2021/07/22 09:28]
clayton added some text/instructions
tina4:basic-routing [2022/07/18 19:19] (current)
nealryan
Line 7: Line 7:
 Consider the following folder structure and the routes you can hit up in the browser. Consider the following folder structure and the routes you can hit up in the browser.
  
-  * src/templates/index.html ->  [[http://localhost:7145/]] or [[http://localhost:7145/index]] +^ Directory      ^ URL       ^ URL 2          ^ 
-  src/templates/store/index.html -> [[http://localhost:7145/store]] or [[http://localhost:7145/store/index]] +src/templates/index.html    [[http://localhost:7145/]]    [[http://localhost:7145/index]]       | 
-  src/templates/store/shop.html -> [[http://localhost:7145/store/shop]]+src/templates/store/index.html    [[http://localhost:7145/store]] [[http://localhost:7145/store/index]]       | 
 +src/templates/store/shop.html    [[http://localhost:7145/store/shop]]     | 
  
 <WRAP center round info> <WRAP center round info>
Line 19: Line 20:
 The folders are simply suggested folders where you can place php files to manage your routing.  Any php file place in the routing folder and sub folders will automatically be parsed and run when Tina4 is hit up. The folders are simply suggested folders where you can place php files to manage your routing.  Any php file place in the routing folder and sub folders will automatically be parsed and run when Tina4 is hit up.
  
-Try placing the following code in a php file of your choice in the routes folder+Try placing the following code in a php file of your choice in the routes folder.
  
-<code php src/routes/someroute.php>+<code php someroute1.php>
 <?php <?php
 +
 \Tina4\Get::add ("/test/route", function(\Tina4\Response $response, \Tina4\Request $request) { \Tina4\Get::add ("/test/route", function(\Tina4\Response $response, \Tina4\Request $request) {
-    return $response ("Hello World!");+    return $response ("Hello World!", HTTP_OK, TEXT_HTML);
 }); });
 </code>   </code>  
Line 41: Line 43:
 \\ \\
 A route with inline parameters can be composed as follows A route with inline parameters can be composed as follows
-<code php src/routes/someroute.php>+<code php someroute2.php>
 <?php <?php
 +
 \Tina4\Get::add ("/test/route/{name}",function($name, \Tina4\Response $response, \Tina4\Request $request) { \Tina4\Get::add ("/test/route/{name}",function($name, \Tina4\Response $response, \Tina4\Request $request) {
-  return $response ("Hello {$name}!");+  return $response ("Hello {$name}!", HTTP_OK, TEXT_HTML);
 }); });
 </code>   </code>  
  
 **A POST ROUTE looks as follows and will need a FORM KEY token to accept POSTS to it for CORS prevention** **A POST ROUTE looks as follows and will need a FORM KEY token to accept POSTS to it for CORS prevention**
-<code php src/routes/someroute.php>+<code php someroute3.php>
 <?php <?php
 +
 \Tina4\Post::add ("/test/post", function(\Tina4\Response $response, \Tina4\Request $request) { \Tina4\Post::add ("/test/post", function(\Tina4\Response $response, \Tina4\Request $request) {
-    return $response ("Hello {$request->param["someInput"]}!");+    return $response (["Hello{$request->params['someInput']}!"], HTTP_OK, TEXT_HTML);
 }); });
 </code> </code>
  
 ** Routing directly to a class ** ** Routing directly to a class **
-<code php src/routes/someroute.php>+<code php someroute4.php>
 <?php <?php
 +
 \Tina4\Get::add("/test", ["TestClass", "someRouter"]); \Tina4\Get::add("/test", ["TestClass", "someRouter"]);
        
Line 67: Line 72:
    }    }
 } }
- 
 </code> </code>
Powered by ComboStrap