Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从cakephp2中的routing(routes.php)文件调用内联函数?_Php_Laravel_Cakephp_Routing_Inline Functions - Fatal编程技术网

如何从cakephp2中的routing(routes.php)文件调用内联函数?

如何从cakephp2中的routing(routes.php)文件调用内联函数?,php,laravel,cakephp,routing,inline-functions,Php,Laravel,Cakephp,Routing,Inline Functions,我想调用routes.php文件中定义的内联函数 我试过这些代码: Router::connect('/test', function () { return 'test';exit;}); Router::connect('/test', function () { echo 'test';exit;}); 但是当我访问localhost/cakephp/test时,我得到了错误: Error: Cannot use object of type Closure as arra

我想调用routes.php文件中定义的内联函数

我试过这些代码:

Router::connect('/test', function () {    return 'test';exit;});
Router::connect('/test', function () {    echo 'test';exit;});
但是当我访问localhost/cakephp/test时,我得到了错误:

 Error: Cannot use object of type Closure as array
File: /var/www/html/massmobile/lib/Cake/Routing/Router.php
Line: 348

Notice: If you want to customize this error message, create app/View/Errors/fatal_error.ctp
在laravel()中,我们可以从路由文件调用内联函数。在cakephp中也可以这样做吗

在cakephp中也可以这样做吗

是的,但不是在CakePHP2

使用CakePHP3。见文件的第1部分。如果您拥有和/或Cake2的文档,它也会告诉您无法通过关闭

结论:提高你的文档阅读技能。对于这些问题,没有比快速查看API文档或代码中的方法签名本身更简单的解决方案了。它将告诉您可以传递哪些参数

另外,我建议您了解CakePHP是如何工作的,而不是像其他框架API那样尝试使用它的API。这是行不通的,而且这种假设相当幼稚。它们有不同的方法(简化:约定优于配置vs配置优于约定),它们的API也不同

在cakephp中也可以这样做吗

是的,但不是在CakePHP2

使用CakePHP3。见文件的第1部分。如果您拥有和/或Cake2的文档,它也会告诉您无法通过关闭

结论:提高你的文档阅读技能。对于这些问题,没有比快速查看API文档或代码中的方法签名本身更简单的解决方案了。它将告诉您可以传递哪些参数

另外,我建议您了解CakePHP是如何工作的,而不是像其他框架API那样尝试使用它的API。这是行不通的,而且这种假设相当幼稚。它们有不同的方法(简化:约定优于配置vs配置优于约定),它们的API也不同