Call function from "views" - 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: Call function from "views" (/showthread.php?tid=19795) Pages:
1
2
|
Call function from "views" - El Forum - 06-19-2009 [eluser]Thorpe Obazee[/eluser] you can call model methods from views like in the controller as per MVC. Code: $this->yourmodel->get_the_settings('name'); I don't think you can do that with a controller. Call function from "views" - El Forum - 06-19-2009 [eluser]Mareshal[/eluser] I tried that before reading your post. Thank you anyway. In a model I wrote the function I needed, then $this->load->model('md'); echo $this->md->my_f("something"); echo because my_f has a return at end. thank you Call function from "views" - El Forum - 06-19-2009 [eluser]n0xie[/eluser] [quote author="Mareshal" date="1245419071"]Ok, my mistake. "I want to pass some post variables to the controller FROM view file without putting them into url or sessions." sorry. [/quote] You mean you want to read the $_POST array from your controller? You can use Code: $this->input->post('field'); Call function from "views" - El Forum - 06-19-2009 [eluser]Thorpe Obazee[/eluser] [quote author="Mareshal" date="1245419650"]I tried that before reading your post. Thank you anyway. In a model I wrote the function I needed, then $this->load->model('md'); echo $this->md->my_f("something"); echo because my_f has a return at end. thank you[/quote] no problem Call function from "views" - El Forum - 06-19-2009 [eluser]Mareshal[/eluser] problem was solved with a model. Edit: I think wasn't solved. Something is not working: I have in my model this: Code: <?php and in views/main_index.php I have this: Code: $this->load->model('dates'); and doesn't want to work. Quote:A PHP Error was encountered In my controller if I write the last code is working, but in views... Call function from "views" - El Forum - 06-19-2009 [eluser]Mareshal[/eluser] Oh dear, my mistake again. Models can't be loaded in views, I think. So I loaded my model in controller constructor, and now is working. |