Welcome Guest, Not a member yet? Register   Sign In
Bringing Model into Scope
#1

[eluser]RJ[/eluser]
Hello,

To bring an object into scope I'm doing this:
Code:
function Worldpay_model()
    {
        parent::Model();
        $this->load->model('dealer_model', 'dealer');
        $this->msisdn = $this->dealer->vars['msisdn'];
        $this->unitid = $this->dealer->vars["unitid"];
        echo $this->msisdn;
        echo $this->unitid;
    }

But I get errors undefined property on dealer and trying to get property of non-object. This object is previously loaded in the controller. What am I doing wrong?

Quote:Message: Undefined property: Worldpay_model::$dealer
Message: Trying to get property of non-object

Thanks.
#2

[eluser]pistolPete[/eluser]
Have a look at

- forums/viewthread/64031/
- forums/viewthread/63953/
#3

[eluser]RJ[/eluser]
I tried the code below, I wouldn't think you have to bring in the super object with a model, only a library. Attempting to load super into model below, new error

Quote:Message: Uninitialized string offset: 0

Code:
class Worldpay_model extends Model
{
/**
* -------------------------------------------------------------------------
*    Worldpay Params
* -------------------------------------------------------------------------
*/    
    var $msisdn;
    var $MC_vatnr;
    var $unitid;
    private $CI;
    
/**
* -------------------------------------------------------------------------
*    Worldpay Constructor
* -------------------------------------------------------------------------
*/    
    function Worldpay_model()
    {
        parent::Model();
        $this->CI =& get_instance();
        
        $this->CI->load->model('dealer_model');

// ERROR APPLIES TO THESE TWO CALLS
        $this->msisdn = $this->CI->dealer_model->vars["msisdn"];
        $this->unitid = $this->CI->dealer_model->vars["unitid"];
// END
        
        echo $this->msisdn;
        echo $this->unitid;
    }
#4

[eluser]TheFuzzy0ne[/eluser]
What's the output you get with this version of your method (same but with var_dump()s added:

Code:
function Worldpay_model()
{
    parent::Model();
    $this->CI =& get_instance();
    
    $this->CI->load->model('dealer_model');

    $this->msisdn = $this->CI->dealer_model->vars["msisdn"];
    $this->unitid = $this->CI->dealer_model->vars["unitid"];
        
    var_dump($this->CI->dealer_model->vars["msisdn"]);
    var_dump($this->CI->dealer_model->vars["unitid"]);
}
#5

[eluser]RJ[/eluser]
Result - string(0)""

Which is odd because I use the same logic in a method located in my controller like below:
Code:
$fields = $this->suw->print_fields(
                                                $this->build_fields(),
                                                $this->dealer->countries,
                                                $this->dealer->vars["hcolor"],
                                                $this->dealer->vars["acolor"],
                                                $this->lang->lang()
                                                );

This having the dealer_model loaded in /shop/device where shop is controller and device is method of shop controller. Usage in controller/metod is:

Code:
$this->load->model('dealer_model','dealer');    // load dealer
# Set dealer params
$this->dealer->dealer_model($dealer);        // passes db info to dealer model for processing
#6

[eluser]TheFuzzy0ne[/eluser]
On your example of how you load your dealer model, you pass is some initialization parameters, but you aren't doing that when you load it in the model. Is that what the problem is?
#7

[eluser]RJ[/eluser]
No that sets some variables in the dealer object from controller. Those are what I'm trying to access; preexisting dealer object with variables already set. Is that not possible from the model?
#8

[eluser]TheFuzzy0ne[/eluser]
It is, which is why I don't understand why it's not working. Have you tried loading the model from the controller instead of from within another controller?
#9

[eluser]RJ[/eluser]
Moved to loading after $this->dealer->dealer_model is called in controller method

Code:
$this->dealer->dealer_model($dealer);        // passes db info to dealer model for processing
$this->load->model('Worldpay_model', 'worldpay');     // load wp

Eliminated dealer object call in Model. Working now.




Theme © iAndrew 2016 - Forum software by © MyBB