Welcome Guest, Not a member yet? Register   Sign In
$this->load->view() is executing the view() method in current controller
#1

[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?
#2

[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?
#3

[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 ?




Theme © iAndrew 2016 - Forum software by © MyBB