Welcome Guest, Not a member yet? Register   Sign In
Problems with a model

I'm currently rewriting a website, and so far 90% of the work is done and working without issues. I've decided to add a new facility which calls some code that already works, but for some reason it just doesn't want to play ball. Even though I've tried to load the model in the code, it still doesn't play ball... e.g.
and I get
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined property: reminders_model::$groups_model
Filename: models/reminders_model.php
Line Number: 308
(crashing out on the $users=$this->groups_model->get_group_users($groupid)Wink

The load model was added to see what happens as this is already loaded in the controller, and the same function called from another controller works 100%?

Any clues/ideas are welcome as I'm stuck on this now.

[eluser]Phil Sturgeon[/eluser]
Does the file exist and has it got the right name?

groups_model.php should contain Class Groups_model.

File does exist and used elsewhere, and in my debug log
DEBUG - 2009-01-09 14:29:49 --> Model Class Initialized
DEBUG - 2009-01-09 14:29:49 --> groups_model created
ERROR - 2009-01-09 14:29:49 --> Severity: Notice  --> Undefined property: reminders_model::$groups_model /home/reminder/public_html/test/system/application/models/reminders_model.php 306
I can even see it's getting loaded!

wrong forums.

what is in reminders_model.php? Why is it calling that instead of groups_model? Are you loading reminders_model in groups_model? Do you have the matching filenames?

reminders_model deals with the reminders being generated, and calls the groups_model to get a list of users for this reminder. All file names are correct and works elsewhere correctly, this is the odd thing!

(Wrong forum? can someone move it then)

[eluser]Michael Wales[/eluser]
Could you paste the code of groups_model - I have a feeling reminders_model is going to end up being a child object of groups_model, rather than a child of the CodeIgniter super object.

class groups_model extends Model {
    function groups_model()
        // Call the Model constructor
        log_message('debug', 'groups_model created');


class reminders_model extends Model {
    function reminders_model()
        // Call the Model constructor
        log_message('debug', 'reminders_model created');
Both just extend base classes - I didn't realise you could have "Child objects though"? How does this happen, and how do you prevent it? And how can I check?

(Thanks for move)

[eluser]Michael Wales[/eluser]
You're not showing us enough... it appears as if you have these two classes within the same file, you are loading the groups_model file (with the Load class, so it will create an instance of this object) but you aren't loading the reminders_model anywhere (as if you assume, since it's part of the groups_model's file an instance will be created).

I'm sure I'm 100% off the mark here, but you just aren't helping us help you. Without any code we can't possibly tell you what's going on here.

I'm just trying to figure out where reminders_model is coming from in this error. We need to see where groups_model and reminders_model are being loaded/instantiated and we need to see where reminders_model is calling groups_model.

function add($aid)
    //  special function to allow a non user to add a reminder to 4rd party based on request id

        if ($aidinfo===FALSE) redirect ('');  // does not exist so go to front page
        $data["remindertype"]=$this->reminders_model->get_reminder_type($aidinfo->Type); // load the reminder type data

        $this->form_validation->set_rules('fmonth', 'Month', 'required');
        $this->form_validation->set_rules('fyear', 'Year', 'required');
        $this->form_validation->set_rules('fday', 'Day', 'required|callback_check_remind_date');

        $validated = $this->form_validation->run();
        if ($validated)
            log_message('debug', '*** 3rd party! add_remindertype '.$aid.' which has been validated');

            $this->session->set_flashdata('user', $aidinfo->ForUserID);

            $this->reminders_model->add_reminder($data["remindertype"],$event,$reminder); // snd data to model for update
This is the routine I'm working on, and the groups_model (separate file to the reminders_model) is loaded only after the validation has taken place.

The add_reminder saves an event to the table, then an update is called to put correct reminder dates in, lastly reminds are created for everyone attached to that group of reminders. This all takes place in the reminders_model till :-
    function add_reminders_for_event($eventid,$eventdate,$firstreminddays,$secondreminddays,$remindforname,$remindforrelid,$notes,$groupid)
    // doesn't matter if we are adding a new, or updating an old
    // rather than checking finding and updating reminders
    // simply delete any attached to this event, and add new ones
    // event date should be the next date for this event and should also be a class
        log_message('debug', '*** add_reminders_for_event '.$eventid);
        // get users to create reminders for

It dies there at getting data from the groups model.

[eluser]Michael Wales[/eluser]
Yeah, as I thought.

// The $this in this line is referrign to reminders_model
  // We need to make it refer to the CodeIgniter super object

New code:
function add_reminders_for_event ($eventid,$eventdate,$firstreminddays,$secondreminddays,$remindforname,$remindforrelid,$notes,$groupid) {
  $CI =& get_instance();
  $users = $CI->groups_model->get_group_users($groupid);

You can also make this a class variable, if you will be calling model-to-model a lot. get_instance() is just one of the global functions CodeIgniter provides that returns the CI super object.

Theme © iAndrew 2016 - Forum software by © MyBB