質問

I try silex for building my application. When I try to test my first application, I get an error like this:

Fatal error: Class 'Silex' not found in /opt/local/apache2/htdocs/silex/try.php on line 5

and this is my code :

<?php
  #require_once __DIR__.'/silex.phar';  
  require_once 'phar://'.__DIR__.'/silex.phar/vendor/.composer/autoload.php';  
  #require_once 'phar://'.__DIR__.'/silex.phar/autoload.php';  
  $app= new Silex/Application();  
  $app->get('hello/{name}',function($name) use($app){  
     return 'Hello ' .$app->escape($name);  
  });  
  $app['debug'] == true;  
  $app->run();  
?>

I've searched for my error in a search engine and I have some suggestions like to add this code in php.ini:

extension=phar.so  
phar.readonly = Off  
phar.require_hash = Off  
detect_unicode = Off

But I still get the same error when I test in a web browser. What's your suggestion?

役に立ちましたか?

解決

Initially it looks like your line:

$app= new Silex/Application();

Should actually read (note the backslash):

$app= new Silex\Application();

\ is the namespace separator, what your code is doing is is running new Silex then dividing that by Application(), and as class Silex does not exist, compilation fails.

Hopefully that solves the problem!

Also:

I think the line $app['debug'] == true; should be $app['debug'] = true; (single equals) - double equals is an equality test, single equals is assignment.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top