问题描述
我正在开发一个带有 silex-skeleton 的最新版本的项目.尝试使用共享方法时显示以下错误:
代码:
$app['login'] = $app->share(function() use($app) {返回新模型\用户模型($app);});
错误:尝试在类Silex\Application"上调用方法share"
对此失败的任何建议或可能的原因
Silex 2.0 正在使用 Pimple 3.0 删除了 shared
方法,现在所有服务默认共享,如果你想要一个新的例如,您必须调用 版本变更日志中所述的 factory
方法2.0.
所以如果你想要一个登录服务,你应该像这样创建它:
您可以直接在 它的 GitHub 存储库上查看 3.0 Pimple 版本的文档>
I am developing a project with silex-skeleton in its most recent version. When trying to use the share method shows me the following error:
Code:
$app['login'] = $app->share(function() use($app) {
return new Model\UserModel($app);
});
Error:Attempted to call method "share" on class "Silex\Application"
Any suggestions or possible cause of this failure
Silex 2.0 is using Pimple 3.0 which has removed the shared
method, now all services are shared by default, if you want a new instance you must call the factory
method as stated in the changelog for version 2.0.
So if you want a login service you should create it like this:
<?php
$app['login'] = function($app) {
return new Model\UserModel($app);
};
You can take a look at the docs for the 3.0 Pimple version directly on it's GitHub repository
2.0 has reached prod status as of 2016-05-18
这篇关于试图调用方法“share"在类“Silex\Application"上在 Silex 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!