CodeIgniter Forums
using APPPATH - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: using APPPATH (/showthread.php?tid=87996)



using APPPATH - richb201 - 07-04-2023

I am moving code over from a Ci3 app to Ci4. I understand the APPPATH needs to be set in index.php. The reason I need it is that I have the following lines in my main Controller.
require APPPATH."../assets/MyReport.php";
require APPPATH."../assets/MyNexusReport.php";
require APPPATH."../assets/MyDashboard.php";
require APPPATH."../assets/MyDashboard2.php";
require APPPATH."../assets/OfficeHours.php";
require APPPATH."../assets/MySetup.php";
require APPPATH."../assets/MyValidate.php";
require APPPATH."../assets/MyExportExcel.php";
require APPPATH."../assets/MyExport6765.php";
require APPPATH."../assets/MyFormUser.php";
require APPPATH."../assets/MyFormUserE.php";
require APPPATH."../assets/MyFormRegister.php";
require APPPATH."../assets/MyFormAdminLogin.php";
require APPPATH."../assets/MainReport.php";
require APPPATH."../assets/MyExecutive_summary.php"; 

Is APPPATH still used or is there some place other than index.php were I set the APPPATH? Is this change covered in the docs?


RE: using APPPATH - luckmoshy - 07-04-2023

There are at least 4 Global directories in CI4  which are WRITEPATH,FILEPATH,ROOTPATH and APPPATH so for you to get your assets you shoul use ROOTPATH  https://codeigniter.com/user_guide/general/common_functions.html?highlight=global#ROOTPATH

APPPATH indicates inside APP and ROOTPATH The path to the project root directory


also, these files can be registered to autoload if you like

PHP Code:
<?php

namespace Config;

use 
CodeIgniter\Config\AutoloadConfig;

class 
Autoload extends AutoloadConfig
{
    // ...
    public $classmap = [
        
///inside APP
        'Markdown' => APPPATH 'ThirdParty/markdown.php',
    
//in the root directory    app,Myfiles
       
'Markdown' => ROOTPATH 'Myfiles/MyExecutive_summary.php.php',
    ];

    // ... 



RE: using APPPATH - richb201 - 07-04-2023

Thanks. But it seems that my ROOTPATH is not being set correctly. Here is the error:
require(/var/www/../assets/MyReport.php): failed to open stream: No such file or directory

it should be /var/www/ci4/Views/MyReport.php

I then tried using APPPATH instead and get this error:
require(/var/www/app/../assets/MyReport.php): failed to open stream: No such file or directory

it should be /var/www/ci4/app/../assets/MyReport.php

In both cases I am missing the '/ci4'

In what file can I fix up both the APPPATH and ROOTPATH?

Same error!


RE: using APPPATH - kenjis - 07-04-2023

(07-04-2023, 08:15 AM)richb201 Wrote: I am moving code over from a Ci3 app to Ci4. I understand the APPPATH needs to be set in index.php. The reason I need it is that I have the following lines in my main Controller.
require APPPATH."../assets/MyReport.php";
...

What do you mean? Why do you need to set APPPATH in index.php?

APPPATH is set in system/bootstrap.php by the framework.


RE: using APPPATH - kenjis - 07-04-2023

APPPATH is the path to the app directory.
https://codeigniter4.github.io/CodeIgniter4/general/common_functions.html#APPPATH