CodeIgniter Forums
Visibility of Methods in Models - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Visibility of Methods in Models (/showthread.php?tid=66920)



Visibility of Methods in Models - solanogalema - 12-18-2016

   
 Question?

If i load model (Xpto_model) that extends MY_Model, that extends CI_Model and call a protected method from MY_Model.
Should be work?
$this->load->model("Xpto_model");
$this->Xpto_model->protectedMethodFromMyModel();

Its actual working, but i think it should not work. Because if i transfer the method to Xpto_model a correct errors appears.


RE: Visibility of Methods in Models - HTLove - 12-19-2016

Cạn lời...

You can't call $this->Xpto_model->protectedMethodFromMyModel(); because protectedMethodFromMyModel() method protected,
Method cant call is extends class.

Link: http://php.net/manual/en/language.oop5.visibility.php
http://stackoverflow.com/questions/4361553/php-public-private-protected


RE: Visibility of Methods in Models - solanogalema - 12-19-2016

(12-19-2016, 06:17 AM)HTLove Wrote: Cạn lời...

You can't call $this->Xpto_model->protectedMethodFromMyModel(); because protectedMethodFromMyModel() method protected,
Method cant call is extends class.

Link: http://php.net/manual/en/language.oop5.visibility.php
http://stackoverflow.com/questions/4361553/php-public-private-protected

Thanks for your help.
But the point is: Why is running without errors when i call protected method from MY_model?
public function doSomething(){
        $this->load->model("Product_model", "product_m");
        $this->product_m->publicMethodMyModel();
        $this->product_m->protectedMethodMyModel(); // here is the problem. This call should generate an error but it is not.
        $this->product_m->publicMethodProduct();
//     $this->product_m->protectedMethodProduct();
}