Welcome Guest, Not a member yet? Register   Sign In
Entity class not working on 2 module
#1

hi all,

i recently implement entity to my project, i successfull setup it to work with the backend module, but when i call that model in the frontend module, it does not return an entity object, i return the normal object. Here is my project structure and code

my folder structure 
[Image: eb-err-entity.png]

when i run and debug the code in acp module
[Image: eb-err-entity-2.png]
as you can see, i got my post item return successfully in entity object

but when i call it in my site module
[Image: eb-err-entity-1.png]
it does not return entity object but a normal object, does any one have this problem? or i missing something?
Reply
#2

Your not giving enough information like what is site a module?

If your calling a Site Module then you need to tell it where the Entity is.

use app/Modules/Acp/Entities/entityName;
What did you Try? What did you Get? What did you Expect?

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

(10-15-2020, 11:27 PM)InsiteFX Wrote: Your not giving enough information like what is site a module?

If your calling a Site Module then you need to tell it where the Entity is.

use app/Modules/Acp/Entities/entityName;

as i mention in my structure, acp is a module stand for admin panel and site is a module stand for frontend

in both controller acp/post and site/post i use just 1 model: Modules\Acp\Models\PostModel; ( as you can see in the 2,3 picture )

and there are 2 different result, the result in Acp/post controller give me the entity object but the result in Site/post controller return the normal object
Reply
#4

Our you defining the use clause like I showed?

If the Entity is in the acp then the use clause should be like below.

Site/Post controller
use app/Modules/Acp/Entities/entityName;
use app/Modules/Acp/Models/PostModel;

Is that how you have your Site controller?
What did you Try? What did you Get? What did you Expect?

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

(10-16-2020, 11:19 AM)InsiteFX Wrote: Our you defining the use clause like I showed?

If the Entity is in the acp then the use clause should be like below.

Site/Post controller
use app/Modules/Acp/Entities/entityName;
use app/Modules/Acp/Models/PostModel;

Is that how you have your Site controller?

yes, you're right, in my Site/Controller i used: use app/Modules/Acp/Models/PostModel; and call that model to load data

and in my postModel code i return Entity class, my code is like this:


PHP Code:
namespace Modules\Acp\Models;

use 
CodeIgniter\Model;
use 
Modules\Acp\Entities\Post;

class 
PostModel extends Model
{
    protected $table 'post';
    protected $primaryKey 'id';

    protected $returnType Post::class;
    protected $useSoftDeletes true


With this code when i call the model in Acp/Controller it successfully return the Entity class

I also try to create new PostModel in Site/Model and new Entity in Site/Entities, my new model code is like:


PHP Code:
namespace Modules\Site\Models;

use 
CodeIgniter\Model;
use 
Modules\Site\Entities\Post;

class 
PostModel extends Model
{
    protected $table 'post';
    protected $primaryKey 'id';

    protected $returnType  'Modules\Site\Entities\Post';
    protected $useSoftDeletes true

but when i try to call the new model it does not return the entity object, i got the same problem as above. I dont know what wrong...
Reply
#6

To me it looks like your name space is off because your Modules folder is under the app folder.

PHP Code:
namespace Modules\Site\Models;

// should be
namespace app\Modules\Site\Models

So all your namespaces and use clauses should start with app\
What did you Try? What did you Get? What did you Expect?

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

(This post was last modified: 10-16-2020, 09:31 PM by tmtuan.)

(10-16-2020, 07:46 PM)InsiteFX Wrote: To me it looks like your name space is off because your Modules folder is under the app folder.

PHP Code:
namespace Modules\Site\Models;

// should be
namespace app\Modules\Site\Models

So all your namespaces and use clauses should start with app\
that namespace work perfect with my acp and other stuff, because i declare my module in my autoload like this:
PHP Code:
$psr4 = [
            
'App'         => APPPATH,                // To ensure filters, etc still found,
            
APP_NAMESPACE => APPPATH,                // For custom namespace
            
'Config'      => APPPATH 'Config',
            
'Modules\Site' => APPPATH 'Modules/Site',
            
'Modules\Acp' => APPPATH 'Modules/Acp',
            'Modules\Auth' => APPPATH 'Modules/Auth',
        ]; 
Reply
#8

Then I it looks like you may have found a bug in the Entities, I would file an issue
on GitHub for it.
What did you Try? What did you Get? What did you Expect?

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

(10-17-2020, 04:18 AM)InsiteFX Wrote: Then I it looks like you may have found a bug in the Entities, I would file an issue
on GitHub for it.
i also think my Entities have problem, so i double check it and run debug, but there's no problem on it, because the entities work good when i call it in Modules\Acp, all function work well in it

It just have the problem when i use in Modules\Site
Reply




Theme © iAndrew 2016 - Forum software by © MyBB