Problems with set_include_path()

Asked

Viewed 51 times

3

I find it difficult to make a single configuration file (responsible for __autoload) can be used either by the files that are in the root, or by the ones that are in the folder admin.

The root directory contains the folders app, public and admin. The briefcase app contains the configuration file and directories model, view and controller.

In the admin folder I want to maintain a similar structure, with an app folder, containing directory controller and view.

The intention is to make the files inside admin/app/controller access the classes through the configuration file contained in raiz/app and this is the only file responsible for including the classes. For this, I used the inclusion of the folders root, raiz/app and raiz/app/model via set_include_path() (I use the XAMPP).

Well, if the file is calling the class is in the root, or in the raiz/app/controller, the class is instantiated, but nothing works in the raiz/admin, or raiz/admin/app/controller.

For you to understand how I was doing, I had a configuration file for each folder as well as a app, armed with controller, model and view for each application (horrible to give maintenance) and worked.

  • It is impossible to provide a "solution" because it needs more details, although it is well explained, it takes a lot of time to read, reread and try to interpret all this. I suggest you try to standardize the development of your applications with standards such as PSR: http://www.php-fig.org/psr/psr-4/ .

  • A work friend was having a similar problem because his xamp was outdated with php and was conflicting with global variables when calling functions from one directory to another

1 answer

0


The problem was fixed by adding constants in the startup file, containing the path not only to the directory with the classes, but to controllers and views.

Example:

<?php
    // um monte de instruções
    define('APP_DIR', $_SERVER['DOCUMENT_ROOT'] . '/app/');
    define('HOST_MODEL', APP_DIR . 'model/');
?>

I hope you help someone.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.