Undefined Property

Asked

Viewed 104 times

0

Could someone help me? I’m racking my brain here to try to solve this problem, but I’m not getting it.

The error is as follows:

Severity: Notice

Message: Undefined property: AccountProfile::$AccountProfileModel

Filename: access/Accountprofile.php

Line Number: 33

Backtrace:

File: /application/public/caritas/application/controllers/access/Accountprofile.php
Line: 33
Function: _error_handler

File: /application/public/caritas/index.php
Line: 323
Function: require_once

In this case, this is my Controller:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

include_once(CONTROLLER_BASE);
/**
* @class Account Profile
*/
class AccountProfile extends ControllerBase
{
    /**
     * @method Construct
     */
    public function __construct()
    {
        parent::__construct();
        $this->LoadModel(Model::$ACCOUNTPROFILE);
        $this->CheckToken();
    }

    public function Index()
    {        
        $data = null;            
        $this->GetAll();                   
    }

    public function GetAll()
    {        
        if($this->hasToken)
        {   
            try
            {       
                if(isset($this->limit))
                {
                    $obj = $this->AccountProfileModel->GetAllAccountProfile($this->total, $this->limit, $this->index);
                }
                else $obj = $this->AccountProfileModel->GetAllAccountProfile($this->total);

                $this->SetSuccess($obj); 
            }
            catch (Exception $e)
            {
                log_message("error", "ERROR GETALL ACCOUNTPROFILE: " . $e->getMessage());
                $this->SetError();
            }            
        }
        else $this->SetForbidden();
    }

Already my Model:

require_once MODEL_BASE;

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class AccountProfileModel extends ModelBase 
{    
    function __construct() 
    {
        parent::__construct(DBGroup::DB_MICROSERVICE_API, Model::$ACCOUNTPROFILE['model']);
    }

    public function GetAllAccountProfile(&$total, $limit = null, $index = null)
    {
        $rows = NULL;   

        $total = $this->db->count_all_results($this->GetDefaultTable(), TRUE);

        $this->db->select($this->GetDefaultTable().".accountprofileid");    
        $this->db->select($this->GetDefaultTable().".accountid");
        $this->db->select($this->GetDefaultTable().".profileid");
        $this->db->select($this->GetDefaultTable().".status");
        $this->db->select($this->GetDefaultTable().".dateupdate");
        $this->db->select($this->GetDefaultTable().".accountupdateid"); 
        $this->db->select("a.name as accountupdatename");   
        $this->db->join('account a', 'a.accountid = '.$this->GetDefaultTable().'.accountupdateid', 'left');                        
        $this->db->order_by($this->GetDefaultTable().'.name');

        if(isset($limit))
        {
            $offset = $limit * $index;
            $result = $this->db->get($this->GetDefaultTable(), $limit, $offset);
        }
        else $result = $this->db->get($this->GetDefaultTable());

        if (Tools::IsValidObject($result))
        {
            $rows = $result->result();
        }

        return $rows;
    }
}

This is the line of my model helper:

public static $ACCOUNTPROFILE   = array('model' => 'accountprofile',    'path' => 'access',             'dbgroup' => DBGroup::DB_MICROSERVICE_API);
  • You are referencing $this->total in your controller, within your call, and it does not exist in the model, you must pass the same parameters!

  • Hello, @Diêgocorreiadeandrade, thank you very much for trying to help, but this referencing yes, look: Controller: if(isset($this->limit)) { $obj = $this->Accountprofilemodel->Getallaccountprofile($this->TOTAL, $this->limit, $this->index); Model: public Function Getallaccountprofile(&$TOTAL, $limit = null, $index = null) ?

  • don’t need that $this friend, just pass the normal variables,

  • Even so, as it turned out: Controller: if(isset($this->limit))&#xA; {&#xA; $obj = $this->AccountProfileModel->GetAllAccountProfile($total, $limit, $index);&#xA; }&#xA; else $obj = $this->AccountProfileModel->GetAllAccountProfile($total);&#xA;&#xA; $this->SetSuccess($obj); Model: public function GetAllAccountProfile(&$total, $limit = null, $index = null)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.