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/19 18:04]
andre
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) { + 
-    return $response ("Hello World!");+\Tina4\Get::add ("/test/route", function(\Tina4\Response $response, \Tina4\Request $request) { 
 +    return $response ("Hello World!", HTTP_OK, TEXT_HTML);
 }); });
 </code>   </code>  
  
-Now lets test it by spinning up a web-server & hitting up [[http://localhost:7145/test/route]]  +Now lets test it by spinning up a built in web-server
 ===== Spinning Up A Web-Server ===== ===== Spinning Up A Web-Server =====
 Spin up a web-server by entering :  Spin up a web-server by entering : 
Line 36: Line 38:
 </code> </code>
  
-Ensure you are using the correct port number above as per your  serverenv, mail settings etc.  +Hit up [[http://localhost:7145/test/route]] in your Web Browser ( e.g. FireFoxChrome etc)
-\\+ 
 +===== Various Routing Examples =====
 \\ \\
 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) { + 
-  return $response ("Hello {$name}!");+\Tina4\Get::add ("/test/route/{name}",function($name, \Tina4\Response $response, \Tina4\Request $request) { 
 +  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 66: Line 72:
    }    }
 } }
- 
 </code> </code>
- 
- 
Powered by ComboStrap