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

Phalcon Tutorial - Basic Problem

Hello,

I am following the steps of the tutorial - basic (https://docs.phalcon.io/3.4/en/tutorial-base) and I have a problem when I am trying to use the hyperlink to move to another page it does not work properly (does not load).

I will attach a link below with screenshots from the code and the page if someone can help me to find the error I will appreciate it

https://imgur.com/a/L3TXlUy



1.4k

Try linkto "tutorial/signup"

Or

Use .htaccess file in your root directory. If you use Apache Something like this:

  • app/
  • public/ ---index.php
  • .htaccess

.htacess file must contains

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule  ^$ public/    [L]
RewriteRule  (.*) public/$1 [L]
</IfModule>

Then you page will be available at https://localhost/tutorial.

edited Feb '19

I tried to change linkto "tutorial/signup" but it did not work

Also I tried

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule  ^$ public/    [L]
RewriteRule  (.*) public/$1 [L]
</IfModule>

but it didnt work I dont know if i made a mistake will writing it , i am attaching a link of a photo if you want to chek the code

https://imgur.com/a/9bonTST

Try linkto "tutorial/signup"

Or

Use .htaccess file in your root directory. If you use Apache Something like this:

  • app/
  • public/ ---index.php
  • .htaccess

.htacess file must contains

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule  ^$ public/    [L]
RewriteRule  (.*) public/$1 [L]
</IfModule>

Then you page will be available at https://localhost/tutorial.

I'm new with phalcon and I'm trying to learn and routing is not on the current chapter and I'm trying to take it step by step

why not use Phalcon\Mvc\Router ? https://docs.phalcon.io/3.4/en/routing

Can you share your public/index.php code ?

<?php

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

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

$loader = new Loader();

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

$loader->register();

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

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

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

$application = new Application($di);
try {
    $response = $application->handle();
    $response->send();
} catch (\Exception $e){
    echo 'Exception: ', $e->getMessage();
}

Can you share your public/index.php code ?



1.4k

I tried to change linkto "tutorial/signup" but it did not work

  1. Check https://localhost/tutorial/signup directly from browser. Do you see your form?

  2. If you use apache - check "AllowOverride All" option in your apache2.conf(or httpd.conf) in virtualhost block. For enable .htaccess support.

  3. View source page https://localhost/tutorial/public - what you see in href="..."?
  1. No i cant see the page if i go directly through the link

  2. I will try to check the apache2.conf you said

  3. <a href="/signup">Sign Up Here!</a>

I tried to change linkto "tutorial/signup" but it did not work

  1. Check https://localhost/tutorial/signup directly from browser. Do you see your form?

  2. If you use apache - check "AllowOverride All" option in your apache2.conf(or httpd.conf) in virtualhost block. For enable .htaccess support.

  3. View source page https://localhost/tutorial/public - what you see in href="..."?


1.4k
  1. No i cant see the page if i go directly through the link

  2. I will try to check the apache2.conf you said

  3. <a href="/signup">Sign Up Here!</a>

Do you setup your server with it instruction? https://docs.phalcon.io/3.4/en/webserver-setup#apache

I forgot about the second file .htaccess in /public. Create it near index.php file

edited Feb '19

you mean somethink like that...????

https://imgur.com/a/fAFKFFI

  1. No i cant see the page if i go directly through the link

  2. I will try to check the apache2.conf you said

  3. <a href="/signup">Sign Up Here!</a>

Do you setup your server with it instruction? https://docs.phalcon.io/3.4/en/webserver-setup#apache

I forgot about the second file .htaccess in /public. Create it near index.php file



1.4k
edited Feb '19

you mean somethink like that...????

https://imgur.com/a/fAFKFFI

  1. First .htaccess file must be placed in /tutorial. And contents

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule   ^$ public/    [L]
    RewriteRule   ((?s).*) public/$1 [L]
    </IfModule>

    This file will be send all queryes to the /tutorial/public dir.

  2. Second file .htaccess in /tutorial/public, near index.php. And contents

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

    This re-writes all the URIs to the public/index.php file

  3. Now if you load page https://localhost/tutorial/...anythings... - file /tutorial/public/index.php catches it and began work.

Nope still nothing

https://imgur.com/fsMr8dJ

you mean somethink like that...????

https://imgur.com/a/fAFKFFI

  1. First .htaccess file must be placed in /tutorial. And contents

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule   ^$ public/    [L]
    RewriteRule   ((?s).*) public/$1 [L]
    </IfModule>

    This file will be send all queryes to the /tutorial/public dir.

  2. Second file .htaccess in /tutorial/public, near index.php. And contents

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

    This re-writes all the URIs to the public/index.php file

  3. Now if you load page https://localhost/tutorial/...anythings... - file /tutorial/public/index.php catches it and began work.

Are you using Phalcon devTools ?

sorry for the silly question but how can i check that ?

Are you using Phalcon devTools ?



84

Hi, I have same problem. anyone find how to fix it ?



84
edited Apr '19

Ok, Found a problem here. for some reason it looks like apache on ubuntu did not load mod rewrite automaticaly. Due to configuration is changed at ubuntu apache2.4 you need to create a symlink in /etc/apache2/mods-enabled to point at /etc/apache2/mods-available/rewrite.load to enable the mod rewrite and restart the apache2 service.

mark this as solved.

This is a very extraordinary difficulty. And truely we're 99.9% positive that before a positive second it never seemed. We suppose it started out to expose up after an upgrade on our site.