0

I downloaded Phalcon from official website I copied php_phalcon.dll file to my xampp's php/ext directory Edited the php.ini file located at D:\xampp\php\php.ini. and add there line extension=php_phalcon.dll at the end of the file. I Restarted apache server and computer several times.

When I write phpinfo() to my code it seems phalcon was installed enter image description here enter image description here Unfortunatelly Whan I try to run some code like

<?php 

try {
    // Autoloader
    $loader = new \Phalcon\Loader();
    $loader->registerDirs([
        '../app/controllers/',
        '../app/models/'
    ]);
    $loader->register();

    // Dependency Injection
    $di = new \Phalcon\DI\FactoryDefault();
    $di->set('view', function() {
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir('../app/views');
        return $view;
    });

    // Deploy the App
    $app = new \Phalcon\Mvc\Application($di);
    echo $app->handle()->getContent();

} catch(\Phalcon\Exception $e) {
    echo $e->getMessage();
}

?>

I get this error Fatal error: Uncaught Error: Class 'Phalcon\Loader' not found in D:\xampp\htdocs\php-learning\public\index.php:4 Stack trace: #0 {main} thrown in D:\xampp\htdocs\php-learning\public\index.php on line 4

I also tried to follow the steps from tutorial on Phalcon ofical website where code looks somehow like this

<?php

use Phalcon\Di\FactoryDefault;
use Phalcon\Loader;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Application;
use Phalcon\Url;

// Define some absolute path constants to aid in locating resources
define('BASE_PATH', dirname(__DIR__));
define('APP_PATH', BASE_PATH . '/app');

// Register an autoloader
$loader = new Loader();

$loader->registerDirs(
    [
        APP_PATH . '/controllers/',
        APP_PATH . '/models/',
    ]
);

$loader->register();

$container = new FactoryDefault();

$container->set(
    'view',
    function () {
        $view = new View();
        $view->setViewsDir(APP_PATH . '/views/');
        return $view;
    }
);

$container->set(
    'url',
    function () {
        $url = new Url();
        $url->setBaseUri('/');
        return $url;
    }
);

$application = new Application($container);

try {
    // Handle the request
    $response = $application->handle(
        $_SERVER["REQUEST_URI"]
    );

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

But didn´t help. What I am doing wrong?

6
  • For windows, you need to download the right phalcon dll file to match your architecture and php version. This is an older video, but the concept remains the same: vimeo.com/… Based on your screenshot, it looks like you need VC15, probably NTS, php 7.4, and x64:github.com/phalcon/cphalcon/releases
    – Kevin Y
    Jul 1, 2022 at 21:07
  • sorry, looks like you need TS. (not NTS)
    – Kevin Y
    Jul 1, 2022 at 21:17
  • 1
    From download page, they said "The PSR extension is required to be loaded before Phalcon. Please ensure that it is available in your system". Do you installed it? And I recommend you to follow the document especially basic tutorial.
    – vee
    Jul 1, 2022 at 22:11
  • ya, need psr and pdo extensions. load them before phalcon
    – Kevin Y
    Jul 1, 2022 at 22:34
  • Things might get complicated with Tread Safe php as well. I'd almost reinstall xampp as NTS. Almost everyone uses the NTS php build. There's some bugs with phalcon in TS mode such as where every second request on top of the first can seg fault rooted in zephir.
    – Kevin Y
    Jul 1, 2022 at 22:46

1 Answer 1

0

You have Phalcon installed successfully. However the namespace should be changed:

  • Moved Phalcon\Loader to Phalcon\Autoload\Loader #15797

please refer to the change log enter link description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.