php - CodeIgniter Hello World MVC with two models -


my ci controller looks this:

 // controller.  class hello extends ci_controller  {      public function one($name)      {          $this->load->model("hello_model");           $profile = $this->hello_model->getprofile("me");          //$profile2 = $this->hello_model->otheraction();           $this->load->view('header');           $data = array("name" => $name);          $data['profile'] = $profile;          $this->load->view('one.html', $data);      }  } 

and here is/are model(s)

 class hello_model extends ci_model  {      public function getprofile($name)      {          return array("fullname" => "martin", "age" => 28);      }  }   class hello_model_2 extends ci_model  {      public function otheraction()      {          echo "data";      }  } 

when enable $profile2 statement , visit controller in browser, find error message in apache error log:

[mon apr 01 ...] [error] [client 127.0.0.1] php fatal error:  call undefined method hello_model::otheraction() in  /.../codeigniter_2.1.3/application/controllers/hello.php on line x 

where x line of profile2 statement.

can not have 2 classes in "model"-file? btw, .php files called in ci-speak? modules?

each file must have 1 model only.

http://ellislab.com/codeigniter/user-guide/general/models.html

instead create method in same class like-

class hello_model extends ci_model  {      public function getprofile($name)      {          return array("fullname" => "martin", "age" => 28);      }       public function otheraction()      {          echo "data";      }  } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -