mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-15 18:23:26 +03:00
Readded csrf_token helper function - don't run away this time.
This commit is contained in:
26
README.md
26
README.md
@@ -249,7 +249,8 @@ We recommend that you add these helper functions to your project. These will all
|
||||
To implement the functions below, simply copy the code to a new file and require the file before initializing the router or copy the `helpers.php` we've included in this library.
|
||||
|
||||
```php
|
||||
<?php
|
||||
use Pecee\SimpleRouter\SimpleRouter as Router;
|
||||
|
||||
/**
|
||||
* Get url for a route by using either name/alias, class or method name.
|
||||
*
|
||||
@@ -269,7 +270,7 @@ To implement the functions below, simply copy the code to a new file and require
|
||||
*/
|
||||
function url($name = null, $parameters = null, $getParams = null)
|
||||
{
|
||||
return SimpleRouter::getUrl($name, $parameters, $getParams);
|
||||
return Router::getUrl($name, $parameters, $getParams);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,7 +278,7 @@ function url($name = null, $parameters = null, $getParams = null)
|
||||
*/
|
||||
function response()
|
||||
{
|
||||
return SimpleRouter::response();
|
||||
return Router::response();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -285,7 +286,7 @@ function response()
|
||||
*/
|
||||
function request()
|
||||
{
|
||||
return SimpleRouter::request();
|
||||
return Router::request();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -297,8 +298,7 @@ function request()
|
||||
*/
|
||||
function input($index = null, $defaultValue = null, $methods = null)
|
||||
{
|
||||
if($index !== null)
|
||||
{
|
||||
if ($index !== null) {
|
||||
return request()->getInput()->get($index, $defaultValue, $methods);
|
||||
}
|
||||
|
||||
@@ -313,6 +313,20 @@ function redirect($url, $code = null)
|
||||
|
||||
response()->redirect($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current csrf-token
|
||||
* @return string|null
|
||||
*/
|
||||
function csrf_token()
|
||||
{
|
||||
$baseVerifier = Router::router()->getCsrfVerifier();
|
||||
if ($baseVerifier !== null) {
|
||||
return $baseVerifier->getToken();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
14
helpers.php
14
helpers.php
@@ -63,4 +63,18 @@ function redirect($url, $code = null)
|
||||
}
|
||||
|
||||
response()->redirect($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current csrf-token
|
||||
* @return string|null
|
||||
*/
|
||||
function csrf_token()
|
||||
{
|
||||
$baseVerifier = Router::router()->getCsrfVerifier();
|
||||
if ($baseVerifier !== null) {
|
||||
return $baseVerifier->getToken();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user