Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Current »

Description


mixed route(string $route, Closure $callback)


 

Create a route for your app, which is placed in your start.php.

Parameters


$route

URL route to connect to your callback
 

$callback

Callback function to call when your route has been reached.

Examples


<?php

// Example URL: http://localhost/foo
route('/foo', function() {
   echo "Hello World!";
});



/**
 * Example URL: http://localhost/bar/{{ custom_id }}
 *
 * Here we pass a 2nd segment to our route, which could
 * be the ID of an item. Since its unique we prefix it
 * with a colon
 */
route('/bar/:id', function($id) {
   echo $id;
});



/**
 * Example URL: http://localhost/posting
 *
 * You can also chain other methods to your route.
 * Here we use the accept() method to only accept
 * POST requests to this route.
 */
route('/posting', function() {
   echo "Accepting only POST data.";

   print_r($_POST);
})->accept('POST');

Methods


MethodDescriptionUsageReturns
accept(string|array $methods)

Define what HTTP request methods are accepted.

Can be passed as a single string or an array of

accepted methods.

route('/posting', function() {
   echo "Accepting only POST data.";

   print_r($_POST);
})->accept('POST');
\Core\Route (object)

 

 

  • No labels