Welcome Guest, Not a member yet? Register   Sign In
Have I done something dumb?
#1

[eluser]nealumney[/eluser]
Hi folks,

I have created a model and controller with the same name! Is this allowed? Does CI get confused when I write something like:
Code:
if ($this->contact->save($save) )

where save is a funcion in the model? I don't have a save function in the controller.

Thanks,

Neal
#2

[eluser]ggoforth[/eluser]
This is a good question...I'm not positive, however I can offer the following Logic:

If your calling a method called save in the model contact, CI should know it's calling the model. If you were calling a local method "save" you would write:

Code:
$this->save($save)

Your code is clearly calling an external model (or lib) named contact that you have loaded via the load() functions of CI.

So, I think your ok. Again, I might be wrong, but seems like you should be fine.

Greg
#3

[eluser]Dam1an[/eluser]
Would PHP not throw an error as you have given to classes the same name?
I always use the _model suffix for models and then just alias them to the name I want in the controller... Never had any problems yet
#4

[eluser]ggoforth[/eluser]
Ah, good point. I do the _model suffix as well, so I had never ran into the problem. But you bring up a pretty obvious point....although, if he's already doing it, there must be something going on there.
#5

[eluser]Dam1an[/eluser]
Hmmm... if PHP isn't throwing the error, he mmust have called it something else and aliased it as well...
Maybe he was just concerned if it wouldn't know which method to go for (controller or model) which has been cleared up now Smile
#6

[eluser]nealumney[/eluser]
Actually, I don't think CI like controllers and models having the same name! I changed the model to: contact_model, and everything works as fine. Effectively the I just had a blank screen (probably my settings) no php errors were shown.

Still, I am continuing to learn something new every day now (and I'm only 51). Thanks for your help

Neal
#7

[eluser]Colin Williams[/eluser]
You can't have two classes with the same name in PHP, CI or not.




Theme © iAndrew 2016 - Forum software by © MyBB