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

Invo local not working

Hello,

I have a local instance of INVO. At first it seems to be working correctly however, when i nvaigate to about and then back to home it gives the default Apache 404. Also, whenever I try navigate to a non-existant controller/action it gives a blank page not a 404 like I would expect.

This is my configuration (Using directory /sites in Vagrant vm):

Apache config:

DocumentRoot /sites/invo-master/public
<Directory /sites/invo-master/public>
...

invo-master/app/config.ini:

...
baseUri        = /

Maybe someone can see what I am doing wrong?



43.9k

Hi,

try with:

DocumentRoot /sites/invo-master

<Directory /sites/invo-master>

I'm afraid the problem still persists, I still get the standard Apache 404 and calling other controllers directly still routes to a blank page



43.9k

I never use vagrant boxes.

Tell me, if you point your browser to https://localhost, does it serve by default the content of the "sites" directory ?

How do you want to acces to invo app : through https://localhost, htpp://localhost/sites, https://localost/sites/invo-master, https://localhost/invo-master ?

Right now it is accessed via https://127.0.0.1:8080 as port 8080 is the out-going port for port 80 of the vm.



43.9k

well, I think that the correct configuration should be for serving invo app on https://127.0.0.1:

baseUri = /

and in apache config:

DocumentRoot /sites/invo-master

<Directory /sites/invo-master>

So, if it's not working:

  • see http response (404 not found, 500 internal server error ...
  • have a look at apache's errors
edited May '15

I moved the sites directory to my host machine and installed the necessary components to see if it was perhaps the vm causing the issues. The navigation seems to work fine now, going from about back to home doesn't cause an Apache 404 anymore. However I cannot force the app to 404, even when i try https://127.0.0.1/foo/foo it simply routes to a blank page. Does anyone else experince this with INVO? I feel it's either my configuration or the dispatcher.

Is there perhaps another example of an app using a dispatcher to handle authentication? I need to create an app for a uni project, it involoves several layers of authentication, it needs to be fast and secure. I thought INVO would be a great base with which to work however I haven't had much success with using it.

P.S. @le51 thank you for your help.

edited May '15

Update

By commenting out the security dispatcher and trying to load https://127.0.0.1/foo/foo it correctly displays the app's 404. So I believe it's infact INVO that is not behaving correctly. Should I try fix it and make a pull request? It would be my first pull request :D

Edit

This is what I changed

app/config/services.php:

...
/**
 * Check if the user is allowed to access certain action using the SecurityPlugin
 */
//$eventsManager->attach('dispatch:beforeDispatch', new SecurityPlugin); // <-- Commented out

/**
 * Handle exceptions and not-found exceptions using NotFoundPlugin
 */
$eventsManager->attach('dispatch:beforeException', new NotFoundPlugin);


3.8k
Accepted
answer
edited May '15

I managed to solve the issue by essentually creating my own NotFoundPlugin that would execute beforeDispatchLoop

    <?php

    use Phalcon\Text;
    use Phalcon\Events\Event;
    use Phalcon\Mvc\Dispatcher;
    use Phalcon\Mvc\User\Plugin;
    use Phalcon\Mvc\Dispatcher\Exception as DispatcherException;

    Class ExistsPlugin extends Plugin {

    /**
     * @param Event $event
     * @param Dispatcher $dispatcher
     * @throws DispatcherException
     */
    public function beforeDispatchLoop(Event $event, Dispatcher $dispatcher) {

        $controller = empty($dispatcher->getControllerName()) ? "" : (APP_PATH . Text::camelize($dispatcher->getControllerName()) . 'Controller') ;
        $action = empty($dispatcher->getActionName()) ? "" : (Text::camelize($dispatcher->getActionName()) . 'Action');

        try {
            // Is the controller defined in the url?
            if ($controller) {
                // Does the defined controller exist?
                if (file_exists($controller)) {
                    // Is the action defined in the url?
                    if ($action) {
                        // Does the defined action exist in the controller?
                        if (method_exists($controller, $action)) {
                        } else {
                            throw new DispatcherException;
                        }
                    }
                } else {
                    throw new DispatcherException;
                }
            }
        }
        catch (Exception $exception) {

            if ($exception instanceof DispatcherException) {
                $dispatcher->forward([
                    'controller'    => 'errors',
                    'action'        => 'error404'
                ]);
            }
            else {
                $dispatcher->forward([
                    'controller'    => 'errors',
                    'action'        => 'error500'
                ]);
            }
        }
    }
    }

Unfortunately it renders NotFoundPlugin almost useless but does however avoid the need for SecurityPlugin from checking the ACL for non-existant controllers/actions.

Could you please critique my code?