首页 / PHP / PHP 5.3.2的Silex问题?
PHP 5.3.2的Silex问题?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP 5.3.2的Silex问题?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1917字,纯文字阅读大概需要3分钟。
内容图文
![PHP 5.3.2的Silex问题?](/upload/InfoBanner/zyjiaocheng/816/3548bd1f1c16445ba90f09e44c2e1d33.jpg)
我尝试了Silex中的示例,并将我的控制器放在一个单独的目录和类中.
默认情况下,控制器方法不会传递Request和Application对象.这适用于我的开发机器,它有5.3.14但不是默认的Ubuntu 5.3.2.它给了我:
PHP Catchable fatal error: Argument 1 passed to Sv\Controller\Index::index() must be an instance of Symfony\Component\HttpFoundation\Request, none given, called in /site/include/app/bootstrap.php on line 23 and defined in /site/include/app/Sv/Controller/Index.php on line 46
这是我的引导程序PHP:
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Sv\Repository\PostRepository;
use Sv\Controller;
$app = new Silex\Application();
// define global service for db access
$app['posts.repository'] = $app->share( function () {
return new Sv\Repository\PostRepository;
});
// register controller as a service
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
$app['default.controller'] = $app->share(function () use ($app) {
return new Controller\Index();
});
$app['service.controller'] = $app->share(function () use ($app) {
return new Controller\Service($app['posts.repository']);
});
// define routes
$app->get('/', 'default.controller:index');
$app->get('/next', 'default.controller:next');
$service = $app['controllers_factory'];
$service->get('/', "service.controller:indexJsonAction");
// mount routes
$app->mount('/service', $service);
// definitions
$app->run();
这是控制器代码:
namespace Sv\Controller;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
class Index
{
public function index(Request $request, Application $app)
{
return 'Route /index reached';
}
public function next(Request $request, Application $app)
{
return 'Route /next reached';
}
}
为什么这不起作用?
我希望这不是阻止我在PHP 5.3.2下使用ZF2的问题…
解决方法:
Silex需要PHP 5.3.3,如您在their composer.json中所见:
"require": {
"php": ">=5.3.3",
...
它还在README file中说明:
Silex works with PHP 5.3.3 or later.
这是因为Symfony2不再支持PHP 5.3.2.
内容总结
以上是互联网集市为您收集整理的PHP 5.3.2的Silex问题?全部内容,希望文章能够帮你解决PHP 5.3.2的Silex问题?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。