CodeIgniter Forums
$this->load->view() is executing the view() method in current controller - 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: $this->load->view() is executing the view() method in current controller (/showthread.php?tid=24692)



$this->load->view() is executing the view() method in current controller - El Forum - 11-17-2009

[eluser]shallway[/eluser]
host php version : 4.4.2
CI version : 1.7.2

Here is my Controller :

Code:
class Question extends Controller{
  function Question(){
    parent::Controller();
  }
  function ask(){
    $this->load->view('question-form');
  }
  function view(){
    if( !$this->uri->segment(3) )
      show_error( 'Question doesn\'t exist' );
    ....
  }
}

I'm using pretty url, so the request to the above controller is like this

Quote:http://mydomain.com/question/ask

Instead of loading the question-form, I god error "Question doesn't exist' which can only be fired by the view method in current controller. so the $this->load->view statement is actually executing the 'view' method!

My uri config for CI is :

$config['base_url'] = "http://mydomain.com/";
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";

not sure it's relevant nor not, tho.

Any ideas?


$this->load->view() is executing the view() method in current controller - El Forum - 11-17-2009

[eluser]shallway[/eluser]
Got the answer from CI documentation, under php 4, 'view' is a reserved word. But still what's weird is that I have another site using the same hosting and same php version and I'm sure there're some controllers having 'view' as a function member, but they're surprisingly working. Any explanation?


$this->load->view() is executing the view() method in current controller - El Forum - 11-17-2009

[eluser]shallway[/eluser]
hmmm .. as I see, CI doc did mention that 'view' can't be used as a Controller name, so I guess using it as a function name is still ok ?