Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

IndexController and View work, but not other links

New install Phalcon 3.2 AWS Ubuntu 16.04 PHP 7 mod rewrite is enabled.

I was trying to basically follow this: https://docs.phalconphp.com/en/3.2/tutorial-base

First my 'old' bootstrap from a phalcon setup i tried last year works, but I couldn't get the 3.2 example one to function.

Second, I can surf to the index controller/view. But a link I made to go ot another controller/view does not.

"The requested URL /user/list was not found on this server." Apache/2.4.18 (Ubuntu) Server at 34.210.155.129 Port 80

The link I setup looks like this: echo $this->tag->linkTo( "user/list", "User List");

Trying to reach the UserController, listAction .

What'd I miss?

edited Jun '17

Its hard to say without seeing your code.

Second, I can surf to the index controller/view. But a link I made to go ot another controller/view does not.

So navigating to directly http://you.tld/user/index works? but http://you.tld/user/list does not work?

What does your bootstrap file look like? are you loading up the URL resolver via phalcon?

Are you runnin a micro app? If so have you efined your routes using hte micro app router?



1.2k
edited Jun '17

Sorry about the absence of code, didn't want to wall-o-text. I changed my folder structure around, I had apps and public under a 'dashboard' folder, like this:

/var
  /www
    /html
      /dashboard
        /apps
        /public
      index.php

It is now:

/var
  /www
    /html
        /apps
        /public
          index.php

Where index.php, the bootstrap, is under /public, like the tutorial says.

Contents of bootstrap:

use Phalcon\Loader;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Application;
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Url as UrlProvider;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;

try {

// Register an autoloader
$loader = new Loader();
$loader->registerDirs(
    [
        '../app/controllers/',
        '../app/models/',
    ]
);
$loader->register();

// Create a DI
$di = new FactoryDefault();

// Setup the view component
$di->set('view', function () {
    $view = new View();
    $view->setViewsDir('../app/views/');
    return $view;
});

// Setup a base URI so that all generated URIs include it
$di->set('url', function () {
    $url = new UrlProvider();
    $url->setBaseUri('/');
    return $url;
});

// Handle the request
$application = new Application($di);

$response = $application->handle();
$response->send();

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

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

It still loads the IndexController, but now it ONLY loads that one. If I surf to serverIP/user/list I get the main index page again. In fact anything I type in goes there.

I put this in my /etc/apache2/apache2.conf

<IfModule mod_rewrite.c>

<Directory "/var/www/html">
    RewriteEngine on
    RewriteRule  ^$ public/    [L]
    RewriteRule  ((?s).*) public/$1 [L]
</Directory>

<Directory "/var/www/html/public">
    RewriteEngine On
    RewriteCond   %{REQUEST_FILENAME} !-d
    RewriteCond   %{REQUEST_FILENAME} !-f
    RewriteRule   ^((?s).*)$ index.php?_url=$1 [QSA,L]
</Directory>

</IfModule>

And I put this in my /etc/apache2/sites-available/000-default.conf

    ServerAdmin [email protected]
    DocumentRoot /var/www/html/public
    DirectoryIndex index.php

    <Directory "/var/www/html/public">
            AllowOverride All
            Options All
            Order allow,deny
            Allow from all
    </Directory>

I'm a Windows networking guy, so all this linux/apache is killing me. :) It's like Kryptonite. But millions (ok, like 12 people) are counting on me...

Thanks for the help!

I am not 100% sure... but this might be a dispatcher issue.

try adding the App dispatcher to your bootstrap.

$di->set('dispatcher', function () {
    $dispatcher = new Dispatcher();
    return $dispatcher;
});


8.4k
Accepted
answer
edited Jun '17

Also try updating your Apache conf file. the one in your public DIR

here is the reference i am using.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

yours is

RewriteRule   ^((?s).*)$ index.php?_url=$1 [QSA,L]

The recommended from Phalcon

RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]


1.2k

Christian, thank you very much for the help. I will try it first thing in the morning tomorrow and reply with what happens.

edited Jun '17

A quick side note.

I HIGHLY recommend using the phalcon-devtools

you can generate a new project with all of thsi stuff bootstrapped properly right out of the gate.

its as simple as $> project [name] [type] [directory] [enable-webtools]

$> phalcon project --name TestingApp --type (cli, micro, simple, multi)

It has automatic Controller creators.

$ phalcon controller --name user

Automatic Model generation based on your connected DB

$ phalcon model --Table_Name

It also has REALLY cool database migration services that you can use to automate your relaese migration of new table changes etc. It saves me SOO much time when rolling out changes to production.

On your dev box. This will take the tables your sepcificy and check for changes from most recently understood definitions and make the change scripts.

$ phalcon migration generate --table[s]  Table_Name_To_Migrate  --no-auto-increment

Then on your production server. Will run from its current phalcon migraiton (stored in .phalcon-migraiton) state up to current.

$ phalcon migration run

Its all super slick and i wish i would have known about it all when i first started using phalcon.



1.2k
edited Jun '17

This did the trick! I don't know where I got that line from, I thought the tutorial, but it's possible I got it from an older version or something.

I saw the dev tools, and they doo look slick. I'm worried it will slow me down, I'm on a very urgent project and need to get coding right away to migrate from php 5.3/Codeigniter, so I skipped over them, possible to my detriment.

Thank you very much for your insight and help. Now I can try to move forward.

-J

Also try updating your Apache conf file. the one in your public DIR

here is the reference i am using.

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

yours is

RewriteRule   ^((?s).*)$ index.php?_url=$1 [QSA,L]

The recommended from Phalcon

RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]

You absolutely don't need them to get up and running. but when your schedules slows down i recomend going back and checking them out. They are really helpful and save me a boatload of time.

This did the trick! I don't know where I got that line from, I thought the tutorial, but it's possible I got it from an older version or something.

I saw the dev tools, and they doo look slick. I'm worried it will slow me down, I'm on a very urgent project and need to get coding right away to migrate from php 5.3/Codeigniter, so I skipped over them, possible to my detriment.

Thank you very much for your insight and help. Now I can try to move forward.

-J

Also try updating your Apache conf file. the one in your public DIR

here is the reference i am using.

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

yours is

RewriteRule   ^((?s).*)$ index.php?_url=$1 [QSA,L]

The recommended from Phalcon

RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]


85

I have the same issue, as driscojs

http://localhost/phalcon_learning/tutorial/signup redirects to http://localhost/phalcon_learning/tutorial/

I double checked .htaccess file - it is the same as @Christian provided. If generate a project via Phalcon DevTools (3.2.0) - everything is OK. So where is a problem?

Ubuntu 16.04 . PHP 7 . XAMP Phalcon DevTools (3.2.0)

Environment: OS: Linux oleksandr-hp 4.4.0-87-generic #110-Ubuntu SMP Tue Jul 18 12:55:35 UTC 2017 x86_64 PHP Version: 7.0.15 PHP SAPI: cli PHP Bin: /opt/lampp/bin/php-7.0.15 PHP Extension Dir: /opt/lampp/lib/php/extensions/no-debug-non-zts-20151012 PHP Bin Dir: /opt/lampp/bin Loaded PHP config: /opt/lampp/etc/php.ini Versions: Phalcon DevTools Version: 3.2.0 Phalcon Version: 3.2.1 AdminLTE Version: 2.3.6

My Bootstrap:

<?php

/* 
 Hello file!
 */

use Phalcon\Loader;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Application;
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Url as UrlProvider;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;

//use Phalcon\Mvc\Dispatcher;

// registering an Autoloader

$loader = new Loader();

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

$loader->register();

// create DI
$di = new FactoryDefault();

// Setup view component
$di->set(
        'view',
        function () {
            $view = new View();

            $view->setViewsDir('../app/views/');

            return $view;
        }

        );

// Setup a base URI
$di->set(
        'url',
        function (){
            $url = new UrlProvider();

            $url->setBaseUri('/phalcon_learning/tutorial/');

            return $url;
        }
);

//// Fixing the dispatcher issue
//
//$di->set('dispatcher', function () {
//    $dispatcher = new Dispatcher();
//    return $dispatcher;
//});

// Initialization of request environment

$application = new Application($di);

try {
    // handle the request
    $response = $application->handle();

    $response->send();

} catch (\Exception $e) {
    echo "Exception: ".$e->getMessage();
}

Thank you in advance.



3.2k
edited Jul '17

Hello

First create a new thread, This one is marked resolved and will be less watched

Your url contains bad characters : %5 (backslash ???) Try rename your application folder without special characters, spaces