无法在浏览器上启动 phalcon 项目

Cannot start phalcon project on browser

我使用 wamp 2.5

我通过将 dll 文件复制到 wamp php 文件夹的 ext 文件夹并通过包含 extension=php_phalcon.dll 编辑 php.ini 文件成功地包含了 phalcon 扩展.我创建了一个简单的项目。但是当我想在浏览器上打开项目时,它会显示文件夹列表而不是所需的页面!这是结果的捕获照片:

那么如何解决呢?

编辑:

这里是 public 文件夹中 index.php 的代码:

<?php

use Phalcon\Loader;
use Phalcon\DI\FactoryDefault;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Application;
use Phalcon\Mvc\Url as UrlProvider;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
use Phalcon\Session\Adapter\Files as SessionFiles;

include("../app/config_const.php");
include("../app/config_inc.php");
include("../app/lib/PSR.php");

require_once RP_BIRT . 'runReport.php';

try {

    // Register an autoloader
    $loader = new Loader();
    $loader->registerDirs(array(
        '../app/controllers/',
        '../app/models/'
    ))->register();

    // Create a DI
    $di = new FactoryDefault();

    // Start the session the first time when some component request the session service
    $di->setShared('session', function () {
        $session = new SessionFiles();
        $session->start();
        return $session;
    });

    // Setup the database service
    $di->set('db', function(){
        $cnx = new DbAdapter(array(
            "host"     => SERVEUR,
            "username" => LOGIN_DB,
            "password" => PWS_DB,
            "dbname"   => BDD
        ));
        return $cnx;
    });

    // Setup the view component
    $di->set('view', function(){
        $view = new View();
        $view->setViewsDir('../app/views/');
        $view->registerEngines(array(
            ".phtml" => 'Phalcon\Mvc\View\Engine\Volt'
        ));
        return $view;
    });

    // Setup a base URI so that all generated URIs include the "phalcon" folder
    $di->set('url', function(){
        $url = new UrlProvider();

        $url->setBaseUri('/'.SITE.'/');
        return $url;
    });

    //Register the flash service with custom CSS classes
    $di->set('flash', function(){
        $flash = new \Phalcon\Flash\Direct(array(
            'error' => 'alert alert-error',
            'success' => 'alert alert-success',
            'notice' => 'alert alert-info',
        ));
        return $flash;
    });

    //Handle the request
    $app = new Application($di);

   echo $app->handle()->getContent();

} catch(\Exception $e) {
     echo "Exception:  ", $e->getMessage();
}

?>

代码../app/config_const.php :

<?php

define("BDD","resto_vide");
define("SITE", "resto");

define('HTTP_MAIN', 'http://'.  $_SERVER["HTTP_HOST"] .'/'.SITE.'/') ;

define('RP_LANG', HTTP_MAIN . 'lang/');
define('RP_SSP', HTTP_MAIN . 'ssp/');

define("SERVEUR",$_SERVER["HTTP_HOST"]);
define("LOGIN_DB","root");
define("PWS_DB","admin");
define("BDD_PORT" ,3306);

define('HTTP_CSS', HTTP_MAIN . "css/");
define('HTTP_JS', HTTP_MAIN . "javascript/");
define('HTTP_IMG', HTTP_MAIN . "images/");
define('HTTP_IMG_LOGO', HTTP_IMG . "logo/");
define('HTTP_IMG_ART', HTTP_IMG . "articles/");
define('HTTP_IMG_TMP', HTTP_IMG . "tmp/");
define('HTTP_IMG_MODE_REGLEMENT', HTTP_IMG . "mode_reglement/");
define('HTTP_IMG_BILLETAGE', HTTP_IMG . "billetage/");
define('HTTP_IMG_CHAMBRE', HTTP_IMG . "chambre/");
define('HTTP_IMG_SALLE', HTTP_IMG . "salle/");
define('HTTP_IMG_TABLE_CLIENT', HTTP_IMG . "table_client/");

define('RP_MAIN', substr($_SERVER["DOCUMENT_ROOT"],-1) == '/' ? $_SERVER["DOCUMENT_ROOT"] . SITE.'/' : $_SERVER["DOCUMENT_ROOT"].'/' . SITE.'/');

define('RP_IMG', RP_MAIN . 'public/images/');
define('RP_IMG_LOGO', RP_IMG . 'logo/');
define('RP_IMG_ART', RP_IMG . 'articles/');
define('RP_IMG_TMP', RP_IMG . 'tmp/');
define('RP_IMG_BILLETAGE', RP_IMG . "billetage/");
define('RP_IMG_CHAMBRE', RP_IMG . "chambre/");
define('RP_IMG_SALLE', RP_IMG . "salle/");
define('RP_IMG_TABLE_CLIENT', RP_IMG . "table_client/");

define('RP_LIB', RP_MAIN . 'app/lib/');
define('CODE_LANG','sess_code_lang');
define('DEFAULT_LANG',  '/fr/');
define('RP_RESSOURCES', RP_MAIN . 'app/ressources/');

define('RP_BIRT' , RP_LIB . 'birt/');

define('RP_REPORT' , RP_MAIN . "public/report/");

// SQL server connection information
$sql_details = array(
    'user' => LOGIN_DB,
    'pass' => PWS_DB,
    'db'   => BDD,
    'host' => SERVEUR
);

?>

代码../app/config_inc.php :

<?php
require_once RP_LIB . 'ressources.lib.php';
require_once RP_LIB . 'pagination.lib.php';
require_once RP_LIB . 'debug.php';
require_once RP_LIB . 'datetime.lib.php';
require_once RP_LIB . 'mysql.lib.php';
require_once RP_LIB . 'string.lib.php';
require_once RP_LIB . 'numberFormat.lib.php';
require_once RP_LIB . 'file.lib.php';

@ini_alter('error_log', RP_MAIN . 'log/error.log');
@ini_alter('default_charset', 'iso-8859-1');
loadRessource('main') ;
loadRessource('global') ;
?>

代码../app/lib/PSR.php :

<?php
/*
  +------------------------------------------------------------------------+
  | Phalcon Framework                                                      |
  +------------------------------------------------------------------------+
  | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com)       |
  +------------------------------------------------------------------------+
  | This source file is subject to the New BSD License that is bundled     |
  | with this package in the file docs/LICENSE.txt.                        |
  |                                                                        |
  | If you did not receive a copy of the license and are unable to         |
  | obtain it through the world-wide-web, please send an email             |
  | to license@phalconphp.com so we can send you a copy immediately.       |
  +------------------------------------------------------------------------+
  | Authors: Piyush Rajesh <mba.piyushgupta@gmail.com>                     |
  |          Serghei Iakovlev <sadhooklay@gmail.com>                       |
  +------------------------------------------------------------------------+
*/
namespace Phalcon\Loader;
use Phalcon\Loader;
/**
 * Phalcon\Loader\PSR.
 * Implements PSR-0 autoloader for your apps.
 *
 * @package Phalcon\Loader
 */
class PSR extends Loader
{
    /**
     * Namespace separator
     * @var string
     */
    protected $namespaceSeparator = '\';
    /**
     * Loads the given class or interface.
     *
     * @param string $className The name of the class to load.
     *
     * @return bool
     */
    public function autoLoad($className)
    {
        // Reduce slashes
        $className = ltrim($className, $this->namespaceSeparator);
        $array = explode($this->namespaceSeparator, $className);
        if (array_key_exists($array[0], $this->_namespaces)) {
            $array[0] = $this->_namespaces[$array[0]];
            $class = array_pop($array);
            array_push($array, str_replace("_", DIRECTORY_SEPARATOR, $class));
            $file = implode($array, DIRECTORY_SEPARATOR);
            foreach ($this->_extensions as $ext) {
                if (file_exists($file . ".$ext")) {
                    require $file . ".$ext";
                    return true;
                }
            }
        }
        // If it did not fit standard PSR-0, pass it on to the original Phalcon autoloader
        return parent::autoLoad($className);
    }
}

您指向的文件夹不包含 index.php,因此 apache 不知道在您的 /public/ 文件夹中查找您的 index.php。您要么需要访问 http://localhost/resto/public/ 来查看您的站点,将 index.php 添加到基本目录(可能只包括 public 中的那个),要么最好是创建一个指向您的 public 文件夹的虚拟主机(这可以满足生产环境中的需要,并使您的业务代码无法直接访问)。

关于在 WAMP 中设置虚拟主机的信息 https://john-dugan.com/wamp-vhost-setup/

虚拟主机应该是什么样子的 Phalcon 文档https://docs.phalconphp.com/en/3.3/webserver-setup#apache