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.

BaseDir and multiple library-dirs?

Hello there, and hello again O:)

As you can see in the title I've got two other (hopefully) little questions I'm confronted with right now and I can't see the solution.

First: I want to upload and work with some files via a form. Everything works. I just wondered if Phalcon can help me to get the right directory. I'm using PHP's function getcwd() and get the directory C:\xampp\htdocs...\public\ But I wonder, if there is a built-in function from Phalcon to get the base-dir (one less than 'public')? I tried getBasePath(), but it returns NULL. Do I have to set this manually with setBasePath()?

Second: I write some libraries. Everything works fine. There will be many more. But I don't understand - using the docs - how to define multiple library directories. I want to seperate the libraries in some sub-dirs. How can I do that? The docs only show (and the invo-example) how to set up one directory for libraries.

Thanks a lot again!

With greets and thanks



17.4k
Accepted
answer

First question:

Did you tried this:

$url = new Phalcon\Mvc\Url();
echo $url->getBaseUri();

Source: http://docs.phalconphp.com/en/latest/reference/url.html#setting-a-base-uri

Second question:

File structure is:

app
    views
    models
    controllers
    library
        Conradaek
    somebodyLabriary
public
    index.php
    js
    img
    files
    css

app/config/loader.php file:

$loader = new \Phalcon\Loader();

$loader->registerNamespaces(
    array(
       'Conradaek\Library1'    => $config->application->libraryDir,
        'SomebodyLabriary'    => $config->application->libraryDir2,
       'Conradaek\Controllers'  => $config->application->controllersDir,
       'Conradaek\Models'  => $config->application->modelsDir,
));

$loader->register();

app/config/config.php file:

return new \Phalcon\Config(array(
    'application' => array(
        'libraryDir'     => __DIR__ . '/../../app/library/Conradaek/',
        'libraryDir2'       => __DIR__ . '/../../app/somebodyLabriary/',
    )
));

Thanks a lot, now I'm using Namespaces, too. Works great!

The way working with Files in PHP I need the full/absolute path (if I understand it right?). That's why I just searched for the right function for the absolute path (at the system): Uploading files, Move files, Read files, Write files ... Thought Phalcon has a built-in function to get the absolute path to the application (e.g. c:\xampp\htdocs\app-dir). So I can append easily something like 'public\files\import\' or 'public\files\export\' ...



17.4k

Hmm, this I don't know. I think you don't need to specify the full path (e.g. ../blabla/file.php) but I may be wrong : /