Welcome Guest, Not a member yet? Register   Sign In
is it really necessary to CD to correct directory to run via CLI?
#1

I'm trying to create some code in my CI3 project that will handle cron jobs and I've read the the docs on running via CLI. Unfortunately, it would appear that CI won't run properly unless the current working directory is set to the directory containing my index.php file. Is that really a requirement? Perhaps there is some way to configure one's CI project so that you don't need to CD to this directory?

My site currently has these settings:
Code:
    $system_path = realpath("../system");
    $application_folder = realpath("../application");
    $view_folder = realpath("../application/views");

I'm thinking I should change those so that they instead define a path relative to my index file:
Code:
$system_path = realpath(dirname(__FILE__) . "/../system");

I definitely think a hard-wired path would be better but expect that this path would need to be defined differently on my workstation vs. my partner's workstation vs. the dev machine vs. the production machine. Any thoughts about whether this is OK or not?
Reply
#2

chdir(dirname(__FILE__));

Done.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB