S
S
sorry_i_noob2018-02-28 15:58:36
Kohana
sorry_i_noob, 2018-02-28 15:58:36

Kohana Am I referring to constants with paths correctly? And if not, how is it right?

Hello. I am writing a website on the Kohana framework. I want to access a file (picture). He has a way. I saved the path in the config file. In the script where I access the file (where its path is needed), I use the following code:

$config = Kohana::$config->load('/paths/user');
$path = $config['IMG_PATH'];

Here is the config code:
define('IMG_PATH', 'files/users/imgs');
return array(
    'IMG_PATH' => IMG_PATH
);

Am I doing the right thing? I apologize for such a question, I'm just a beginner, I want to learn how to write code correctly. Before that, I had a function to get the path to the image. It was in the User model (because the picture is the user's avatar). But I was told that the paths need to be stored in the config file.
And another question. Is there any way I can make it so that I can select constants from a dropdown list (ctrl+space). Rather than open the config file and look at the names of the constants in order to write them as an array key ($config['IMG_PATH']).
And here in the config file I define the constants. Then they need to be written to the return array. Is it possible to somehow determine and immediately send to array? To not repeat. It is only important that you can use a ready-made other constant to define a constant (make a tree). For example, there is a constant IMG_PATH. And based on it, make IMG_PATH_SMALL - which will contain the value of IMG_PATH and plus the string 'small/'.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question