CodeIgniter Forums
Models, Controllers N Bears OH mY!! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Models, Controllers N Bears OH mY!! (/showthread.php?tid=21755)

Pages: 1 2


Models, Controllers N Bears OH mY!! - El Forum - 08-19-2009

[eluser]smatakajr[/eluser]
Hey Guys

I'M reaching out to the forum on this one because i think i have a chicken
and egg situation and i'm quite not understanding why i'm getting a Blank screen

I enabled the logging @ 4 and get a bunch of initialized statements

DEBUG - 2009-08-19 15:20:41 --> Model Class Initialized
DEBUG - 2009-08-19 15:20:41 --> Helpers loaded: url
DEBUG - 2009-08-19 15:20:41 --> Model Class Initialized
DEBUG - 2009-08-19 15:20:41 --> Helpers loaded: url
DEBUG - 2009-08-19 15:20:41 --> Model Class Initialized
DEBUG - 2009-08-19 15:20:41 --> Model Class Initialized
DEBUG - 2009-08-19 15:20:41 --> Helpers loaded: url
DEBUG - 2009-08-19 15:20:41 --> Model Class Initialized
DEBUG - 2009-08-19 15:20:41 --> Helpers loaded: url
DEBUG - 2009-08-19 15:20:41 --> Model Class Initialized
DEBUG - 2009-08-19 15:20:41 --> Model Class Initialized

etc... as this goes on for about 1500 lines


Now I am calling signup/index

in signup/index constructer i have

Code:
$this->load->model("profile_model");
    $this->load->model("inbox_model");


In profile_model construct I Have

Code:
$this->load->model("inbox_model");
        $this->load->model("mail_model");


In inbox_model construct i have

Code:
$this->load->model('mail_model');


In mail_model construct i have

Code:
$this->load->model('affiliates_model');

In the affiliates_model construct i have

Code:
$this->load->model("mail_que_model");
    $this->load->model("inbox_model");


NOW...

When I take out the inbox_model in the affiliates_model
construct I dont get a blank page!

But when I Put it back in i get blank page!


NO PHP ERRORS Either even with E_ALL and log=4


All i can think of is that

inbox_model is loaded in the 1st 2nd and 4th constructors
and that's causing CI to have a brain fart

Please let me know what your thoughts are on this
I have ran across this before and had to sacrifice
model calls because it would blank page me!


Thanks in advance

Rick!


Models, Controllers N Bears OH mY!! - El Forum - 08-19-2009

[eluser]jedd[/eluser]
Wow.

I guess you've answered the question 'Can anything bad happen if I load every model I have from every other model?'

I'd suggest you consider one or more of:
o consolidating your models - inbox and mail seem likely candidates to live together, f.e.
o relocating common functionality into a library (or several)
o relocate very common functions to MY_Model
o redesign your controllers such that they take data from one model and pass to another (generally ends up messy, IMO, but sometimes works very well)
o come up with a .signature that does not occupy half my netbook's horizontal real estate

If you do 2 and 3 well, then you can take 1 to its logical conclusion and have a single model to replace the handful you mention above.


Models, Controllers N Bears OH mY!! - El Forum - 08-19-2009

[eluser]alboyd[/eluser]
That's remarkable stuff.


Models, Controllers N Bears OH mY!! - El Forum - 08-19-2009

[eluser]smatakajr[/eluser]
Hey Jedd

Thanks for the insite, I do indeed think i need to consolidate the mail models
but this code base has become very complex as i have been building it for the past year
and its not as easy as moving around some controlers and consolidating classes per say.

It seems that when I take out the inbox_model in the affiliates_model

It works... maybee there is a 3 set rule or somthing :lol: like I will only load
your models twice or somthing... The problem is that the Inbox model is needed
throughout the application ...

I dont know really.. for now im going to band-aid as i need to make stuff live
and it does work except for this small cavat.

and when i get back on development i will consolidate as much as possible

Is there like an optimizing code ignitor guide??

Thanks
Rick!


Models, Controllers N Bears OH mY!! - El Forum - 08-19-2009

[eluser]smatakajr[/eluser]
BTW i have 2,3, and 4 already in place as MUCH as possible
and i think its time for a bigger notebook!! %-P

Thanks for your help though!!

Rick


Models, Controllers N Bears OH mY!! - El Forum - 08-19-2009

[eluser]jedd[/eluser]
Quote:It works... maybee there is a 3 set rule or somthing :lol: like I will only load
your models twice or somthing...

This really doesn't seem very likely.

Quote:The problem is that the Inbox model is needed throughout the application ...

Then make it a library, and autoload it.

Oh, and I like my netbook. Just the way it is.


Models, Controllers N Bears OH mY!! - El Forum - 08-19-2009

[eluser]smatakajr[/eluser]
OK I dug deeper into my inbox_model (which i had to remove from the affiliates_model)
SO what I did is I left put back inbox_model in the affiliates_model and then removed

$this->load->model('mail_model');

from my inbox_model constructor and put it in the actual function calling the mail_model

Ok man check this shit I finally got PHP to spit out an error
but its not usefull...

Fatal error: Call to a member function _send_system_alert() on a non object

So that tells me that CI cannot initialize the mail_model for some reason
I had this happen in another place a while ago with the mail model
where i was not able to send email alerts because of the blank screen

which was telling me all the time that it wasnt loaded.. Is there any
way in CI to drill down to why the object will not instantiate?

I guess i will have to move the mail_model into a library or somthing
and i bet that will work!!

Glad you like your netbook Smile

Thanks again!
Rick


Models, Controllers N Bears OH mY!! - El Forum - 08-19-2009

[eluser]smatakajr[/eluser]
Ok to screw me up even further, i put back the mail_model in the inbox_model
and i removed the affiliates_model from the mail_model and it all works
so there is defintly a circle here that CI does not like

Here is the flow

signup controler constructer loads

Code:
$this->load->model("profile_model");
$this->load->model("inbox_model");

In profile_model construct loads

Code:
$this->load->model("inbox_model");
$this->load->model("mail_model");

In inbox_model construct loads

Code:
$this->load->model('mail_model');


In mail_model construct loads

Code:
$this->load->model('affiliates_model');

In the affiliates_model construct loads

Code:
$this->load->model("mail_que_model");
$this->load->model("inbox_model");


NOW when i dig to the botom of it
when i take out the affiliates_model from the mail_model

ALL WORKS

I am confused now... really Sad

Thanks For Your Help
Rick!!


Models, Controllers N Bears OH mY!! - El Forum - 08-19-2009

[eluser]jedd[/eluser]
Well, yeah, there's that obvious circular reference in the first message you posted:
Quote:inbox_model loads mail_model

mail_model loads affiliates_model

affiliates_model loads inbox_model

I remember writing code like this before .. though in my defence, I was 12 years old, C64 BASIC didn't really provide an MVC environment, and I hadn't even heard of Dijkstra's seminal work.

What you might want to do .. is, well, you know .. NOT LOAD EVERY FLIPPIN' MODEL EVERYWHERE!

To assist you with that, why don't you, just before you load a model, check if the model is already loaded, say by calling a harmless function within same (there might be a more elegant way of testing if a class is available - I don't know - I tend to NOT LOAD EVERY .. well, you get the idea).


Models, Controllers N Bears OH mY!! - El Forum - 08-19-2009

[eluser]smatakajr[/eluser]
Its not that im loading every model for the fun of it.. and in my defense
i do have a few circle model calls that do work correctly for instanse

my profile_model loads the affilaites_model in a function
and my affiliates_model loads the profile_model in a function

The only difference is thats its not in a constructer

SO

when i try to do this in a constructer with my mail_model it BLANKS
when i try to do this in a function call it NON OBJECTS

I have 8+ years Zend PHP certified coding experince and know how
to structure code.. I already found a few bugs in CI that
i submitted to the BUG forum..

But i think your rite here.. i need to make my mail model a library or consolidate
I think that is whats needed

I have been loading things carefully.. this just tripped me up. I will try to
see whats being loaded and whats not being loaded

Thanks for your help
Rick