views:

455

answers:

2

Hello,

I am looking to build a one page website, that runs on PHP(obviously using codeigniter) and AJAX(supported by jquery), at the moment I have a menu that gets populated from the database, depening on what catergories are selected as being on line, the then build a an url using those results,

if(isset($main_menu)) {
        foreach($main_menu as $row) {
         print "<li><a href='index.php/home/category/$row->category_id'>$row->category_name</a></li>";
        }
       }

My problem is that for this I need to run all the queries from the controller (home) as the user can never leave the page, effectively what I want to happen, is that if the user clicks for example 'Blog', I want a query to run, that selects from the content table in the database all the content that is associated with the blog category I then want to display it in an accordion style, in the 'right-content div' of my site. Then if the the users selects for example inspiration then the query runs again, and adds the inspiration data to same div as the blog data but in its own accordion and not overwriting the blog data.

Is that followable, and more importantly possible, and where the hell would I start, I can use both CodeIgniter and jQuery and really want to push theses technologies and myself.

Thanks

+1  A: 

You just need your AJAX calls to reference unique controllers to keep your MVC separation. This will allow you to keep your backend code maintainable while giving the appearance of a singular front page. You'll need to ensure that no view data is generated by your controller AJAX responses to keep the overhead to a minimum.

You can even load view data as partials and return the string as your AJAX response.

You could have any number of controller/model combinations to support your AJAX requests, i.e.:

  1. /blog/unique-blog-identifier (blog controller, index method, unique-blog-identifier first param)
  2. /news/unique-news-identifier (news controller, index method, unique-blog-identifier first param)
cballou
+1  A: 

I do not know codeigniter, but I would think this is similar in most mvc situations. Where you would have method(s) to return responses to an AJAX request(s).

This is in Ruby and Prototype, but you should get the idea.

Controller:

def get_blog
  # find stuff
  # render or just return either js or json or xml or whatever
end

Javascript:

new Ajax.Request('http://yourdomain.com/get-blog', {
  onSuccess: function(response) {
    // do something with your response data
  }
});

I apologize it's not in PHP.

nowk