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

Where do you normally place your own library?

Hello folks,

I want to make own library, but, I am not sure what is the best place to put.

Should I just create folder call libary under app?

Or, any other option for that?

Thanks,

It really doesn't matter, place it where you find it logical.

I usually create a single root namespace and register it with phalcon loader.

project/
    app/
        ProjectName/
            Controllers/
                IndexController.php
            Models/
                Robot.php
            Library/
                UtilClass.php
                Helper.php
    config/
    view/
<?php

use Phalcon\Loader;

// Creates the autoloader
$loader = new Loader();

// Register some namespaces
$loader->registerNamespaces(
    [
        "ProjectName"    => "app/ProjectName/",
    ]
);

// Register autoloader
$loader->register();

Then anywhere:

$helper = new \ProjectName\Library\Helper();

It's really your personal decision, that's why I like the freedom Phalcon gives :)

Here is a community suggestion which is currnetly being discussed: https://github.com/phalcon/skeleton

My personal structure for most of my projects is as follow:

|--apps
|----|api/ (Api controllers and stuff if needed) 
|----|backend/ (usually the CMS area) 
|----|frontend/ (public controllers etc..) 
|--common
|----|config/ (where i store config files) 
|----|helpers/ (my helper files, those are not models, neither a library. Example: BasketHelper) 
|----|lib/ (own or 3rd party libs) 
|----|scripts/ (cronjobs and other scripts) 
|--data
|----|logs/ 
|----|cache/ 
|----|other_app_generated_stuff/ 
|--public
|----index.php (entry point of application)
|----|assets/ (css, js, images etc...)


2.2k
Accepted
answer

Thank you :) I may take second one this round for my project.