Welcome Guest, Not a member yet? Register   Sign In
using APPPATH
#1
Wink 
(This post was last modified: 07-04-2023, 08:17 AM by richb201.)

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?
proof that an old dog can learn new tricks
Reply
#2

(This post was last modified: 07-04-2023, 09:03 AM by luckmoshy.)

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/gener...l#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',
    ];

    // ... 
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#3

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!
proof that an old dog can learn new tricks
Reply
#4

(This post was last modified: 07-04-2023, 05:37 PM by kenjis.)

(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.
Reply
#5

APPPATH is the path to the app directory.
https://codeigniter4.github.io/CodeIgnit...ml#APPPATH
Reply




Theme © iAndrew 2016 - Forum software by © MyBB