Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

baseUri is not being used when resolving the url #1418

Closed
DeaDSouL opened this issue Jan 16, 2020 · 9 comments
Closed

baseUri is not being used when resolving the url #1418

DeaDSouL opened this issue Jan 16, 2020 · 9 comments

Comments

@DeaDSouL
Copy link

baseUri is not being used when resolving the url. Also, the setting in app\config.php is not right (the default value is / ).

Expected and Actual Behavior

baseUri should be treated as directory/ies not as controllers .

Describe what you are trying to achieve and what goes wrong.
I'm trying to host my phalcon-project inside a folder called phalcons/ . but the thing is that when I try to do that, phalcon fails to recognize 'phalcons/' as directory instead of controller. and it throws this error

PhalconsController handler class cannot be loaded
#0 [internal function]: Phalcon\Mvc\Dispatcher->throwDispatchException('PhalconsControl...', 2)
#1 [internal function]: Phalcon\Dispatcher\AbstractDispatcher->dispatch()
#2 /var/www/html/phalcons/proj1/public/index.php(44): Phalcon\Mvc\Application->handle('/phalcons/proj1...')
#3 {main}

so, phalcon thinks that 'phalcons/' is a controller, while it is a directory .

Provide minimal script to reproduce the issue

mkdir /var/www/html/phalcons
cd /var/www/html/phalcons
phalcon project proj1 simple --enable-webtoos
curl http://localhost/phalcons/proj1

Details

  • System info and versions (if possible): (phalcon info)
Environment:
  OS: Linux 5901e005343d 3.10.0-1062.9.1.el7.x86_64 #1 SMP Fri Dec 6 15:49:49 UTC 2019 x86_64
  PHP Version: 7.3.13-1+0~20191218.50+debian9~1.gbp23c2da
  PHP SAPI: cli
  PHP Bin: /usr/bin/php7.3
  PHP Extension Dir: /usr/lib/php/20180731
  PHP Bin Dir: /usr/bin
  Loaded PHP config: /etc/php/7.3/cli/php.ini
Versions:
  Phalcon DevTools Version: 4.0.1
  Phalcon Version: 4.0.2
  AdminLTE Version: 2.3.6
  • Phalcon Framework version: (php --ri phalcon)
Phalcon is a full stack PHP framework, delivered as a PHP extension, offering lower resource consumption and high performance.
phalcon => enabled
Author => Phalcon Team and contributors
Version => 4.0.2
Build Date => Jan 12 2020 01:52:52
Powered by Zephir => Version 0.12.15-814db50

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.case_insensitive_column_map => Off => Off
phalcon.orm.cast_last_insert_id_to_int => Off => Off
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.column_renaming => On => On
phalcon.orm.disable_assign_setters => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.enable_literals => On => On
phalcon.orm.events => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.exception_on_failed_metadata_save => On => On
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.not_null_validations => On => On
phalcon.orm.update_snapshot_on_save => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.warning.enable => On => On
  • PHP Version: (php -v)
PHP 7.3.13-1+0~20191218.50+debian9~1.gbp23c2da (cli) (built: Dec 18 2019 15:03:24) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.13, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.13-1+0~20191218.50+debian9~1.gbp23c2da, Copyright (c) 1999-2018, by Zend Technologies
Server version: Apache/2.4.25 (Debian)
Server built:   2019-10-13T15:43:54

It happens on windows, ubuntu 18.04 and debian 9

@Jeckerson Jeckerson self-assigned this Jan 16, 2020
@Jeckerson
Copy link
Member

baseUri should be treated as directory/ies not as controllers .
Current choice is basing by developer and his webserver vhost configurations.

If you are using PHP Built-in Web Server, it will work only inside single directory and won't run another project inside another.

In case of Apache, here is example how to make working 2 projects, when one is inside another.

Listen 80
<VirtualHost *:80>
    DocumentRoot "/var/www/html/phalcons"
    ServerName project1.local
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/var/www/html/phalcons/phalcons2"
    ServerName project2.local
</VirtualHost>

@DeaDSouL
Copy link
Author

Hi,
/var/www/html/phalcons is just a normal directory, it is not a phalcon project. While /var/www/html/phalcons/proj1 is a phalcon project.

It is just or organizing my projects.

It is not a project inside a project

@Jeckerson
Copy link
Member

Jeckerson commented Jan 19, 2020

Ah, then this is normal Phalcon behaviour. By default new Router() class is using default routes. So if it can't find controller by URI - it will throw exception.

For that you have 3 options:

  1. Write handling of that exception - https://github.com/phalcon/invo/blob/1.0.0/src/Plugins/NotFoundPlugin.php#L44
  2. Use notFound() method - https://docs.phalcon.io/4.0/en/routing#not-found-404
  3. Use default Controller and action, which will show its output of any not found URI - https://docs.phalcon.io/4.0/en/routing#defaults

@DeaDSouL
Copy link
Author

DeaDSouL commented Jan 19, 2020

but it is not "Not-Found" issue.
the default phalcon routing is just fine.

the thing is that phalcon thinks it's living in the root directory of apache (/var/www/html) which is not correct. that's why it thinks phalcons is a controller and proj1 is an action. which is again not true.
while the truth is phalcons is just a directory, and proj1 is the root directory of the phalcon project.

the $baseUri shloud inform phalcon where it lives. but phalcon some how doesn't care about the value of $baseUri.

that's why I had to replace:

echo $application->handle( $_SERVER['REQUEST_URI'] )->getContent();

with this:

echo $application->handle( substr($_SERVER['REQUEST_URI'], strlen($config->application->baseUri)-1) )->getContent();

in /proj1/public/index.php.

@Jeckerson
Copy link
Member

In that case, you need to submit an issue inside https://github.com/phalcon/cphalcon repository, as it is not devtools issue. Because we are starting to speak about Phalcon itself, not devtools ;)

@Jeckerson
Copy link
Member

Probably related - #1403

@Jeckerson
Copy link
Member

Related - phalcon/cphalcon#14559

@DeaDSouL
Copy link
Author

Related - phalcon/cphalcon#14559

indeed it is.
Thanks

@Jeckerson
Copy link
Member

Closing in favour of phalcon/cphalcon#14559

@niden niden moved this to Released in Phalcon v5 Aug 25, 2022
@niden niden added this to Phalcon v5 Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants