We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

After Generating a Project Skeleton, I can't access the project from the web server

Hello,

thank you for your time. Hope you can help me :/

I decided to learn the Framework Phalcon and then, I bought a French Book about it. I followed it and when I arrived to the Project Creation part, like it's write, I put this on my cmd:

phalcon project hello_world simple --template-engine=volt

and I tried accessing the project from the web server : https://127.0.0.1/html/hello_world/ but when i'm trying accessing the project, I don't get the Congratulation page but an error: HtmlController handler class cannot be loaded

I don't understand, I just generated the page and did nothing so it should work no ?

I searched an equivalent in the official documentation and I found this : https://docs.phalcon.io/4.0/en/devtools#generating-a-project-skeleton so, i generated a project skeleton with the command

phalcon create-project store

and I tried accessing the project from the web server, but I have the same error: HtmlController handler class cannot be loaded

Does anyone have any idea why I have this error ? What I did wrong ? Hope you can help me ! Thank you !



8.4k
Accepted
answer

i think the issue because your project isn't at root folder

you can find the solution here https://forum.phalcon.io/discussion/20291/phalcon-4-new-project-error#C62007

edited Apr '20

i think the issue because your project isn't at root folder

you can find the solution here https://forum.phalcon.io/discussion/20291/phalcon-4-new-project-error#C62007

wow, it worked ! (I'm using Phalcon 3 and not Phalcon 4)

A big thank you ! But every time i create a new project, I will have to make these changes?



8.4k
edited Apr '20

i don't think this applies to phalcon 3.x whats the version of phalcon dev-tools?

and what exactly the change you made ? move project to root folder ? or change public/index.php or app/config/config.php

edited Apr '20

i don't think this applies to phalcon 3.x whats the version of phalcon dev-tools?

and what exactly the change you made ? move project to root folder ? or change public/index.php or app/config/config.php

The version of Phalcon Dev-Tools i'm using is 3.4.11.

I changed this line in /public/index.php

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

to

echo $application->handle($_GET['_url'] ?? '/')->getContent();

and I also changed baseUri in /app/config/config.php to

preg_replace('/public([\/\\\\])index.php$/', '', $_SERVER["PHP_SELF"])

And it worked

Isn't that supposed to work?



8.4k
edited Apr '20

i checked and this issue is because of /app/config/config.php's baseUri

so you revert the changes you made to public/index.php

the template config.php in dev-tools has set baseUri to '/' since 3.4.7

you can change it for future projects if you edit the template file which is located in phalcon_dev_tools_dir/templates/project/simple/config.php

edited Apr '20

i checked and this issue is because of /app/config/config.php's baseUri

so you revert the changes you made to public/index.php

the template config.php in dev-tools has set baseUri to '/' since 3.4.7

you can change it for future projects if you edit the template file which is located in phalcon_dev_tools_dir/templates/project/simple/config.php

So, if I understand well, I need to modify only the baseUri ?

I reverted the changes i made to public/index.php and kept the baseUri modification in /app/config/config.php :

preg_replace('/public([\/\\\\])index.php$/', '', $_SERVER["PHP_SELF"]

But by doing that, it's not working anymore. I get the same error as before : HtmlController handler cannot be loaded :/

Here my /app/config/config.php:

<?php
/*
 * Modified: prepend directory path of current file, because of this file own different ENV under between Apache and command line.
 * NOTE: please remove this comment.
 */
defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..'));
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app');

return new \Phalcon\Config([
    'database' => [
        'adapter'     => 'Mysql',
        'host'        => 'localhost',
        'username'    => 'root',
        'password'    => '',
        'dbname'      => 'test',
        'charset'     => 'utf8',
    ],
    'application' => [
        'appDir'         => APP_PATH . '/',
        'controllersDir' => APP_PATH . '/controllers/',
        'modelsDir'      => APP_PATH . '/models/',
        'migrationsDir'  => APP_PATH . '/migrations/',
        'viewsDir'       => APP_PATH . '/views/',
        'pluginsDir'     => APP_PATH . '/plugins/',
        'libraryDir'     => APP_PATH . '/library/',
        'cacheDir'       => BASE_PATH . '/cache/',
        'baseUri'        => preg_replace('/public([\/\\\\])index.php$/', '', $_SERVER["PHP_SELF"]),
    ]
]);


8.4k

i have to investigate this more

what phalcon version you are using

i have dozens of projects using 3.4.5 and none of them is on root path and have the same issue

the only change i made is the baseUri



8.4k

can you download an older version of phalcon dev tools 3.4.3 and test if the same issue applies

i have to investigate this more

what phalcon version you are using

i have dozens of projects using 3.4.5 and none of them is on root path and have the same issue

the only change i made is the baseUri

I'm using the 3.4.5 phalcon version.

edited Apr '20

can you download an older version of phalcon dev tools 3.4.3 and test if the same issue applies

Since i'm actually using the 3.4.11 version of phalcon Dev-Tools, you want me that I install the 3.4.3 version ?

I can do it but i'm not sure how to install an older version.

I tried with :

{ 
    "require-dev": { 
        "phalcon/devtools": "3.4.3" 
    } 
 }

and I think it worked:

But then, when I try to use the Phalcon command, I have an error message :/

I'm sorry but I have to sleep. Hope you can find what is my problem :/ A huge thank you taking your time trying to find what is this bug. Please continue asking to me to try things if it can help to find what is the problem. I will try what you ask for tommorow.



8.4k

you can download it from github ( click tags for a specific version ) and then extract it into a temp dir then add it to path but you may want to rename phalcon.bat to anything to avoid clashes

edited Apr '20

Good morning :)

I completely deleted the v3.4.11 version and I downloaded the v3.4.3 from: https://github.com/phalcon/phalcon-devtools/releases/tag/v3.4.3.

I put the v3.4.3 in place of v3.4.11 in C:\wamp64\www\phalcon-devtools

I put the repository on my path

but then I still have an error when I try using the Phalcon command:

Could not open input file: C:\wamp64\www\phalcon-devtools\phalcon.php

If I do exactly the same procedure but to put the v3.4.12 (https://github.com/phalcon/phalcon-devtools/releases/tag/v3.4.12), the command Phalcon is working again so it's the v3.4.3 that prevents the proper functioning of the command Phalcon. On the other hand, I tried to generate a project with the v3. 4.12 and after the generation I still getting the error, even with the 3.4.12 :/

Do you want that I try with an other version? Or maybe my installation of the v3.4.3 is wrong?

Though, i has taken little time to register, it is get this kind of information. BeeTV I had too faced the problem. But got over by the above mentioned procedure..So follow my dear friend.



8.4k

try

php C:\wamp64\www\phalcon-devtools\phalcon.php project someProject
edited Apr '20

try

php C:\wamp64\www\phalcon-devtools\phalcon.php project someProject

I need to try it with which version of Phalcon DevTools ?

I tried with the v3.4.3 and I got the same error Could not open input file: C:\wamp64\www\phalcon-devtools\phalcon.php

I also tried it with the v3.4.11 and even if I can access to the phalcon command and generate a project (with the HtmlController class cannot be loaded error), the command you gave me to test is not working. I have Could not open input file: C:\wamp64\www\phalcon-devtools\phalcon.php

Though, i has taken little time to register, it is get this kind of information. BeeTV I had too faced the problem. But got over by the above mentioned procedure..So follow my dear friend.

You had the same problem I have ? You are talking about the procedure talal424 is giving me ? Or an other procedure ?



8.4k
edited Apr '20

i made a couple of tests and here what i got so far

they removed the .php extension phalcon.php to phalcon since 3.4.2

so you could try php C:\wamp64\www\phalcon-devtools\phalcon project someProject to test different versions

i cloned 3.4.3 and 3.4.12 and my already installed version that i can't confirm because it says its 3.4.0 and i know for sure its not and then the cloned 3.4.3 also says its 3.4.0 and yes i checked the php file /scripts/Phalcon/Devtools/Version.php

for each version i made a new project

the original one that i had went smoothly and didn't need to change the baseUri

the 3.4.3 also the same thing working great

but 3.4.12 did not and has the same issue you have. i changed baseUri and exactly like your issue

so now we know for sure the issue is within phalcon dev-tools

edit:

the issue is in /app/config/services.php

just change the uri source to Router::URI_SOURCE_GET_URL or remove the service and use the one already defined in Phalcon\Di\FactoryDefault

$di->setShared('router', function () {
    $router = new Router();
    $router->setUriSource(
        // Router::URI_SOURCE_SERVER_REQUEST_URI
        Router::URI_SOURCE_GET_URL
    );

    return $router;
});

https://docs.phalcon.io/3.4/en/routing#uri-sources

Please note that using Router::URI_SOURCE_GET_URL automatically decodes the Uri, because it is based on the $_REQUEST superglobal. However, for the time being, using Router::URI_SOURCE_SERVER_REQUEST_URI will not automatically decode the Uri for you. This will change in the next major release.

i made a couple of tests and here what i got so far

they removed the .php extension phalcon.php to phalcon since 3.4.2

so you could try php C:\wamp64\www\phalcon-devtools\phalcon project someProject to test different versions

i cloned 3.4.3 and 3.4.12 and my already installed version that i can't confirm because it says its 3.4.0 and i know for sure its not and then the cloned 3.4.3 also says its 3.4.0 and yes i checked the php file /scripts/Phalcon/Devtools/Version.php

for each version i made a new project

the original one that i had went smoothly and didn't need to change the baseUri

the 3.4.3 also the same thing working great

but 3.4.12 did not and has the same issue you have. i changed baseUri and exactly like your issue

so now we know for sure the issue is within phalcon dev-tools

edit:

the issue is in /app/config/services.php

just change the uri source to Router::URI_SOURCE_GET_URL or remove the service and use the one already defined in Phalcon\Di\FactoryDefault

$di->setShared('router', function () {
   $router = new Router();
   $router->setUriSource(
       // Router::URI_SOURCE_SERVER_REQUEST_URI
      Router::URI_SOURCE_GET_URL
   );

   return $router;
});

https://docs.phalcon.io/3.4/en/routing#uri-sources

Please note that using Router::URI_SOURCE_GET_URL automatically decodes the Uri, because it is based on the $_REQUEST superglobal. However, for the time being, using Router::URI_SOURCE_SERVER_REQUEST_URI will not automatically decode the Uri for you. This will change in the next major release.

Because you said that the issue is within phalcon dev-tools, I decided to test each version until I find the version where it no longer work.

I tested the v3.4.3 and it is not working (Could not open input file: C:\wamp64\www\phalcon-devtools\phalcon.php issue)

I tested the v3.4.4 and I got the same issue as the v3.4.3

I tested the v3.4.5 and I got a page with a lot of error

v3.4.5errordisplay

Then I tested with the v3.4.6 and it worked well. I have the Congratulation Page! Finally!

I tested the v3.4.7 and I got the HtmlController handler class cannot be loaded issue.

So, the issue came after the 3.4.6 version since it work on the 3.4.6 and not on the 3.4.7.

To resolve my issue I need to use the v3.4.6 of Phalcon DevTools ! You helped me so much finding to resolve the issue. Thank you !!!

edit:

the issue is in /app/config/services.php

just change the uri source to Router::URI_SOURCE_GET_URL or remove the service and use the one already defined in Phalcon\Di\FactoryDefault

$di->setShared('router', function () {
   $router = new Router();
   $router->setUriSource(
       // Router::URI_SOURCE_SERVER_REQUEST_URI
      Router::URI_SOURCE_GET_URL
   );

   return $router;
});

https://docs.phalcon.io/3.4/en/routing#uri-sources

Please note that using Router::URI_SOURCE_GET_URL automatically decodes the Uri, because it is based on the $_REQUEST superglobal. However, for the time being, using Router::URI_SOURCE_SERVER_REQUEST_URI will not automatically decode the Uri for you. This will change in the next major release.

I just saw your edit, so i use the v3.4.6 or I do what you said to resolve the issue ?



8.4k
edited Apr '20

yes you missed this:

they removed the .php extension phalcon.php to phalcon since 3.4.2

so you could try php C:\wamp64\www\phalcon-devtools\phalcon project someProject to test different versions

you can use the latest version but you would need to make two changes IF your project is not on root path

/app/config/config.php change baseUri to:

preg_replace('/public([\/\\\\])index.php$/', '', $_SERVER["PHP_SELF"])

and either remove the router service or change the uri source in /app/config/services.php to Router::URI_SOURCE_GET_URL

yes you missed this:

they removed the .php extension phalcon.php to phalcon since 3.4.2

so you could try php C:\wamp64\www\phalcon-devtools\phalcon project someProject to test different versions

you can use the latest version but you would need to make two changes IF your project is not on root path

/app/config/config.php change baseUri to:

preg_replace('/public([\/\\\\])index.php$/', '', $_SERVER["PHP_SELF"])

and either remove the router service or change the uri source in /app/config/services.php to Router::URI_SOURCE_GET_URL

I changed the baseUri in /app/config/config.php to :

preg_replace('/public([\/\\\\])index.php$/', '', $_SERVER["PHP_SELF"])

and I changed the Uri Source in /app/config/services.php to Router::URI_SOURCE_GET_URL

And It worked, I've got the Congratulations page ! You are awesome, thank you !

i downloaded the v3.4.3 which you give it works, thanks for the link delta emulator Lite you are awesome

edited Dec '20

It's the way they works - include will encompass content of your different template to a very last template, partial will name volt approach to do all th of it. So pretty similar to above program for beginners, like checkhttps://forum.phalcon.io/discussion/19417/using-ms-sql-server-with-phalcon-3- MyGroundBiz. If you need then update this covered view you ought to to don't forget approximately clearing cache for also final view.

Please note that using Router::URI_SOURCE_GET_URL automatically decodes the Uri, because it is based on the $_REQUEST superglobal. However, for the time being, using Router::URI_SOURCE_SERVER_REQUEST_URI will not automatically decode the Uri for you. This will change in the next major release.