Phalcon Tutorial - Basic Problem

Hello,

I am following the steps of the tutorial - basic (https://docs.phalconphp.com/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



991

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 http://localhost/tutorial.

edited 17d ago

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 http://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.phalconphp.com/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 ?



991

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

  1. Check http://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 http://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 http://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 http://localhost/tutorial/public - what you see in href="..."?


991
  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.phalconphp.com/3.4/en/webserver-setup#apache

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

edited 17d ago

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.phalconphp.com/3.4/en/webserver-setup#apache

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



991
edited 17d ago

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 http://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 http://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 ?