Welcome Guest, Not a member yet? Register   Sign In
Share models,libraries,helpers multi applications
#1

Good morning all

I am in the process of migrating all my applications from CI 3 to CI 4.
However, I encounter a small difficulty.
Indeed, on some projects, I have several applications on the same CI instance. I saw that on CI 4 this was also possible. However, I am wondering how to share models, libraries or helpers between these applications.
On CI 3, I put a shared folder at the root containing models / library / helpers and I loaded this folder in the autoload.
Example of structure on CI 3 :
apps
    frontfoffice
        config
        controller
        ...
    backoffice
        config
        controller
        ...

shared
    helpers
    models
    libraries
system
index.php

I can't get the same thing on CI 4. For example, I would like to share the same model between a backoffice and a frontoffice.
Does anyone have any ideas for me to solve this problem?

Thank you in advance

Pierre

Sorry for my english, I'm frenchWink
Reply
#2

Namespaces

namespace yourName/Shared;

Then you:

use yourName/Shared/helperName etc;
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Thank you for your reply
Sorry I do not really understand do.
I tried to do this but it doesn't work:

namespace App\Controllers;

class Home extends BaseController
{
public function index()
{
$userModel = new \shared\Models\TaskModel();

}

//--------------------------------------------------------------------
}
Reply
#4

Try adding just the use clause first if it still wont work add the psr4 namespaces below and try it.

Did not have time to test this.

PHP Code:
<?php

namespace App\Controllers;

use 
shared\Models\TaskModel;

class 
Home extends BaseController
{
    public function index()
    {
        $userModel = new \shared\Models\TaskModel();
    }

    //--------------------------------------------------------------------
}

// You may need to also add them to the app/Config/Autoload.php.

public $psr4 = [
    'shared\helpers'   => ROOT 'shared/helpers',
    'shared\models'    => ROOT 'shared/models',
    'shared\libraries' => ROOT 'shared/libraries',
]; 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB