我使用wamp 2.5
通过将dll
文件复制到wamp php文件夹的ext文件夹中,并通过包含php.ini
来编辑extension=php_phalcon.dll
文件,我成功地包含了phalcon扩展名。我创建了一个简单的项目。但是,当我想在浏览器中打开项目时,它会显示文件夹列表,而不是所需页面!这是结果的捕获照片:
那么如何解决呢?
编辑:
这是公用文件夹中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);
}
}
答案 0 :(得分:1)
您指向的文件夹不包含index.php,因此apache不知道在/ public /文件夹中查找index.php。您可能需要访问http://localhost/resto/public/来查看您的网站,将index.php添加到基本目录(可能只包含公共目录),或者最好是创建一个指向以下内容的虚拟主机您的公用文件夹(这将完成生产中所需的操作,并使您的业务代码无法直接访问)。
有关在WAMP https://john-dugan.com/wamp-vhost-setup/中设置虚拟主机的信息
关于虚拟主机应为https://docs.phalconphp.com/en/3.3/webserver-setup#apache的内容的Phalcon文档