试图调用方法“share"在类“Silex\Application"上在 Silex 2 [英] Attempted to call method "share" on class "Silex\Application" in Silex 2

查看:15
本文介绍了试图调用方法“share"在类“Silex\Application"上在 Silex 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个带有 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 版本的文档>

PS:请记住,在撰写本文时,Silex 2.0 正在开发,因此请准备好调整您的代码,直到它获得 2.0 稳定版本. 2.0 已于 2016 年 5 月 18 日达到生产状态

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

PS: Keep in mind that, at the time of this writing, Silex 2.0 is in development, so be prepared to adapt your code until it gets a 2.0 stable version. 2.0 has reached prod status as of 2016-05-18

这篇关于试图调用方法“share"在类“Silex\Application"上在 Silex 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆