• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to implement ajax in Code igniter

#11
[eluser]NachoF[/eluser]
[quote author="Bramme" date="1240832645"]
This is my php code, plain and simple:

Code:
function get_html() {
        echo $this->mdl_gallery->get_gallery_html($this->input->post('id'));
    }
The function just calls a method that creates a bunch of html, based on the id. I simply echo that html, no need for views or so (but you could use them offcourse).[/quote]

Thats how I do it.. but I hate having to echo inside my controller... it doesnt seem to follow the whole purpose of MVC... how exactly would you do it if you wanted to use views?

#12
[eluser]Kinsbane[/eluser]
NachoF, like this:
Code:
function get_html() {
$data['gallery'] = $this->mdl_gallery->get_gallery_html($this->input->post('id'));
}

$this->load->view('page', $data);

#13
[eluser]Bramme[/eluser]
A view is in the end nothing more than an echo, only a little more complicated :p

When working with ajax, i tend to go away from mvc and even keep database logic in the controller method... Don't know why, but I like the approach.

#14
[eluser]NachoF[/eluser]
[quote author="Kinsbane" date="1240891353"]NachoF, like this:
Code:
function get_html() {
$data['gallery'] = $this->mdl_gallery->get_gallery_html($this->input->post('id'));
}

$this->load->view('page', $data);
[/quote]
Why is the view loaded outside of the function???... that would lead to everytime the controller is called (regardless of which function) that view being loaded, right?

#15
[eluser]NachoF[/eluser]
[quote author="Bramme" date="1240917955"]A view is in the end nothing more than an echo, only a little more complicated :p

When working with ajax, i tend to go away from mvc and even keep database logic in the controller method... Don't know why, but I like the approach.[/quote]

Well, I have been using datamapper library so even though I dont actually do any query I guess in the background my queries are being done in the controller Sad ... but echoing inside a controller is where I draw the line lol


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.