问题从Slim 2开始

我正在使用Slim Framework 2开发一个Web服务,这是我第一次使用php。 我遇到了Slim对象的问题:</ p>

我的代码是:</ p>

  require'db.php'; 
require' 供应商/苗条/苗条/ Slim / Slim.php';
echo'要求ok';
$ app =新供应商/ slim / slim / Slim();
echo'$ app ok';
</ code> </ pre>

'require'行是可以的。 但他$ app line不起作用我使用相同的路径到Slim.php文件,我也尝试使用这条路径:</ p>

  $ app = / slim  / Slim(); 
</ code> </ pre>

第一个echo正在执行,但第二个echo无效。 我的ws.php文件与供应商文件夹位于同一个directori上:</ p>

  vendor / slim / slim / Slim / 
├──Environment.php
├── 异常
│├──Pass.php
│└──Stop.php
├──Helper
│└──Set.php
├──Http
│├──Cookies.php\ n│├──Headers.php
│├──Request.php
│├──Responx.php
│└──Util.php
├──Log.php
├──LogWriter。 php
├──中间件
│├──ContentTypes.php
│├──Flash.php
│├──SixOverride.php
│├──EleveryExceptions.php
│└──CarsCookie .php
├──Middleware.php
├──Route.php
├──Router.php
├──Slim.php
└──View.php
</ code> </ pre>

$ app = new vendor / slim / slim / Slim(); </ code>是否正确? 我迷失了这个话题。</ p>

使用 Frank Martin 解决方案解决 :</ p>

  require'porpers / autoload.php'; 
$ app = new \ Slim \ App;
</ code> </ pre>

< 相反:</ p>

 需要'vendor / slim / slim / Slim / Slim.php'; 
$ app = new vendor / slim / slim / Slim(); \ n </ code> </ pre>

问候</ p>
</ div>

展开原文

原文

I'm developing a web service using Slim Framework 2, it's the first time I use php. I'm having an issue with the Slim object:

There's my code:

require 'db.php';
require 'vendor/slim/slim/Slim/Slim.php';
echo 'require ok';
$app = new vendor/slim/slim/Slim();
echo '$app ok';

The 'require' lines are ok. But he $app line doesn't work I use the same path to the Slim.php file and also I've tryed to use this path:

$app = /slim/Slim();

The first echo is executing but the second one is not working. My ws.php file is on the same directori as the vendor folder:

vendor/slim/slim/Slim/
├── Environment.php
├── Exception
│   ├── Pass.php
│   └── Stop.php
├── Helper
│   └── Set.php
├── Http
│   ├── Cookies.php
│   ├── Headers.php
│   ├── Request.php
│   ├── Response.php
│   └── Util.php
├── Log.php
├── LogWriter.php
├── Middleware
│   ├── ContentTypes.php
│   ├── Flash.php
│   ├── MethodOverride.php
│   ├── PrettyExceptions.php
│   └── SessionCookie.php
├── Middleware.php
├── Route.php
├── Router.php
├── Slim.php
└── View.php

Is $app = new vendor/slim/slim/Slim(); correct? I'm lost about this topic.

Solved using Frank Martin solution:

require 'vendor/autoload.php';
$app = new \Slim\App;

Instead:

require 'vendor/slim/slim/Slim/Slim.php';
$app = new vendor/slim/slim/Slim();

Regards

1个回答



确保已安装了作曲家依赖项,然后使用它。</ p>

  要求'vendor / autoload.php'; 
$ app = new \ Slim \ App;
</ code> </ pre>
</ div>

展开原文

原文

Make sure you've installed the composer dependencies then use this instead.

require 'vendor/autoload.php';
$app = new \Slim\App;

dpjhq00684
dpjhq00684 没问题:)
4 年多之前 回复
drpph80800
drpph80800 更正:正在使用您的解决方案。 非常感谢你!
4 年多之前 回复
立即提问
相关内容推荐