Welcome Guest, Not a member yet? Register   Sign In
Solution for JS, AJAX, templating for CI

Someone has to take the rains on this topic... My proposed solution is to take some ideas from smartyCMS approach. by doing such we can keep js logic and CSS logic separate from php logic, and make everything JS framework independent.

my ideas would be, if ajax is to be used, simply make a MY_AJAX model that will be loaded to any control that may have ajax, so all Ajax logic and what ever lexicon created can be defind by the user there (or have a few already made for use with JSQuery dojo and so on) then create another directory structor for Views to be such like:

  | +AJAX.php [the logic funtions for ajax comunication]
  | +CSS.php [functions like css_define_id("#sidebar_clock",[widgetname]) os JS wrappers ]
    +-Assets/includes [common elements]
    | |-CSS
    | |-IMAGES
    | |-JS
    +-Widgets [templates to menubars/sidebars anything to plug in]
    +-Templates [each version of a site]
    | |
    | +Default_Name
    |  |-Assets  
    |  |-CSS
    |  |-JS

Example of a Controller:
class Customers extends Controller {

        function __construct() {

        function index()

              $CU_data = $this->db->get('customers');
              $curtime = getdate();
              $w_time['css'] = array(
                                                       'id' => 'currtime'
                                                       'name' = 'currtime' );
              $w_time['data'] = array(
                                                        'data' => getdate();
                                                        'title' => 'The current Date' );
             $data[widget_time] = $w_time;
             $data .= $CU_Data;

       function AJAX()
              $this->ajax->execute_action();  //logic for action or $this->[action]();

     function ADD()
               $this->db->insert('customers') = $this->ajax->data();
               $this->ajax->inerhtml_by_id('#status_message', '<B>ADDED</A>');

            } else {
               $this->db->insert('customers') = $this->posts;
               $data = array('message','Added');


Example of a Widget(filename: standard_dialogbox.widget)
<div id={$css[id]}>

Example of Template(filename: add.php):

{include: file='header.php'}
So this is my dialog box with a widget
{widget: 'standard_dialogbox.widget',$w_time}
{include: file='footer.php'}

extremely tired Will edit post with more examples, but i think this gives the direction

[eluser]Myles Wakeham[/eluser]
Not sure if there is a question here, or if you want general feedback. I do all of my AJAX requests through one central controller so that I can manage security, XSS filtering, etc. in one place. If I did that in all of my controllers, I'd probably go insane.

But it depends on your use-case for this, I guess. Mind you an incoming AJAX request is just another incoming API. What is your strategy when you have to do SOAP, or REST, etc? Do you put that code in all of your controllers as well, or route through one central gatekeeper?


Theme © iAndrew 2016 - Forum software by © MyBB