Javascript 与PHP的yaml中的express app.get(“/:users/:names”)等效?
您知道如何在Node.js/Express/MongoDB堆栈中完成整个过程Javascript 与PHP的yaml中的express app.get(“/:users/:names”)等效?,javascript,php,node.js,yaml,Javascript,Php,Node.js,Yaml,您知道如何在Node.js/Express/MongoDB堆栈中完成整个过程 app.get(“/”){ helloWorld() } app.get(“/:users/:names”){ 脚本() }我使用Symfony读取yaml文件: 代码如下所示: $yamlFile = __DIR__ . '/Routes.yaml'; $routes = yaml::parse(file_get_contents($yamlFile)); // Get routes into an associ
app.get(“/”){
helloWorld()
}
app.get(“/:users/:names”){
脚本()
}
我使用Symfony读取yaml文件:
代码如下所示:
$yamlFile = __DIR__ . '/Routes.yaml';
$routes = yaml::parse(file_get_contents($yamlFile));
// Get routes into an associative array and show the urls.
$handlers = $routes['handlers'];
echo 'Url: ' . $handlers[0]['url'] . "\n";
echo 'Script: ' . $handlers[0]['script'] . "\n";
echo "\n";
echo 'Url: ' . $handlers[1]['url'] . "\n";
echo 'Script: ' . $handlers[1]['script'] . "\n";
/*
Output:
Url: /.*
Script: helloworld.php
Url: /users/names/
Script: getName.php
*/
注意:您需要按如下方式格式化yaml文件,否则它将引发此异常:在映射中无法定义序列项。
handlers:
- url: /.*
script: helloworld.php
- url: /users/names/
script: getName.php
我使用Symfony读取yaml文件: 代码如下所示:
$yamlFile = __DIR__ . '/Routes.yaml';
$routes = yaml::parse(file_get_contents($yamlFile));
// Get routes into an associative array and show the urls.
$handlers = $routes['handlers'];
echo 'Url: ' . $handlers[0]['url'] . "\n";
echo 'Script: ' . $handlers[0]['script'] . "\n";
echo "\n";
echo 'Url: ' . $handlers[1]['url'] . "\n";
echo 'Script: ' . $handlers[1]['script'] . "\n";
/*
Output:
Url: /.*
Script: helloworld.php
Url: /users/names/
Script: getName.php
*/
注意:您需要按如下方式格式化yaml文件,否则它将引发此异常:在映射中无法定义序列项。
handlers:
- url: /.*
script: helloworld.php
- url: /users/names/
script: getName.php