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

some questions about project structure

My purpose is to create a "classified adverts" site with phalcon.

I'm following the "Leaning Phalcon PHP" ebook and has this directory structure:

.
├── composer.json
├── composer.lock
├── config
│   ├── config.php
│   ├── loader.php
│   ├── routing.php
│   └── services.php
├── docs
│   └── learning_phalcon.sql
├── learning_phalcon.dev
├── modules
│   ├── Api
│   │   ├── Config
│   │   │   ├── config.php
│   │   │   ├── routing.php
│   │   │   └── services.php
│   │   ├── Controllers
│   │   │   ├── BaseController.php
│   │   │   └── IndexController.php
│   │   └── Module.php
│   ├── Backoffice
│   │   ├── Config
│   │   │   ├── config.php
│   │   │   ├── routing.php
│   │   │   └── services.php
│   │   ├── Controllers
│   │   │   ├── ArticleController.php
│   │   │   ├── BaseController.php
│   │   │   └── IndexController.php
│   │   ├── Module.php
│   │   └── Views
│   │       └── Default
│   │           ├── article
│   │           │   └── list.volt
│   │           ├── index
│   │           │   └── index.volt
│   │           └── layout.volt
│   ├── Bootstrap.php
│   ├── Core
│   │   ├── Config
│   │   │   ├── config.php
│   │   │   ├── routing.php
│   │   │   └── services.php
│   │   ├── Controllers
│   │   │   ├── BaseController.php
│   │   │   └── IndexController.php
│   │   ├── Managers
│   │   │   ├── ArticleManager.php
│   │   │   └── BaseManager.php
│   │   ├── Models
│   │   │   ├── Article.php
│   │   │   └── Base.php
│   │   └── Module.php
│   └── Frontend
│       ├── Config
│       │   ├── config.php
│       │   ├── routing.php
│       │   └── services.php
│       ├── Controllers
│       │   ├── ArticleController.php
│       │   ├── BaseController.php
│       │   └── IndexController.php
│       ├── Module.php
│       └── Views
│           └── Default
│               ├── article
│               │   └── list.volt
│               ├── index
│               │   └── index.volt
│               └── layout.volt
└── public
    ├── assets
    │   └── default
    │       ├── css
    │       │   ├── lp.backoffice.css
    │       │   └── lp.css
    │       └── js
    │           └── lp.js
    └── index.php

First of all, the code samples in the book don't work. Also I've followed the book carefully and didn't make it work. Simply I can't.

First question: ¿What are the sections core, frontend, api and backoffice for? (each one)

Second question: the author user a file Bootstrap.php in the "modules" folder. Why? Is better? I never could put that to work, I have to use public/index.php or nothing. It always fails when calling $application->handle()->getContent();

Third question: where can I found a good tutorial using some HMVC structure like that in the book? Or good tutorials in general.



85.5k
Accepted
answer

Hi,

What are the sections core, frontend, api and backoffice for? (each one):

  • Core : contains base controllers / services etc. The idea is that you put your base controller there, and EACH AND EVERYONE ( that you want ofc ) will extend this core/base controller. So you can attach a "beforeRoute" listener to all your controllers at once
  • frontend is a module, for example: www.example.com/frontend/index/index, so in this case ( base on your routes ) it will call index controller in frontend module
  • backoffice same as frontend
  • api is also a module, me personally i use it only for ajax requets. So if i have "loadTable" method called from frontend i will make my ajax:
$.ajax("/api/frontend/loadTable")

and i will have loadTableAction in api/FrontendConntroller.php

Second question: the author user a file Bootstrap.php in the "modules" folder. Why? Is better? I never could put that to work, I have to use public/index.php or nothing. It always fails when calling $application->handle()->getContent(); :

I can't really explain it ( since i dont know it perfectly myself ) but i think in bootstrap.php people register their services routes, modules etc....

Third question: where can I found a good tutorial using some HMVC structure like that in the book? Or good tutorials in general.

https://github.com/phalcon/mvc/tree/master/hmvc

you can see many other examples in this repo.

p.s. i havent read the book you are talking about

Cheers!