I use wamp 2.5
I successfully included the phalcon extension by copying the dll
file into the ext folder of the wamp php folder , and editing the php.ini
file by including extension=php_phalcon.dll
. I created a simple project. But when I wanted to open the project on the browser then it shows the list of folders but not the desired page ! Here is the captured photo of the result :
So how to fix it ?
edit :
here is code of the index.php in the public folder :
<?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();
}
?>
code of ../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
);
?>
code of ../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') ;
?>
code of ../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);
}
}
The folder you are pointing to doesn't contain an index.php so apache doesn't know to look in your /public/ folder for your index.php. You'd either need to visit http://localhost/resto/public/ to see your site, add an index.php to the base directory (that maybe just includes the one in public) or what is probably best is to create a virtual host that points to your public folder (this does what it would need to in production and makes your business code not directly accessible).
Info on setting up vhosts in WAMP https://john-dugan.com/wamp-vhost-setup/
Phalcon documention for what a vhost should look like https://docs.phalconphp.com/en/3.3/webserver-setup#apache