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

[eluser]Unknown[/eluser]
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:

Code:
Application
  |
  +-Config
  +-Controlers
  +-Modules
  | +AJAX.php [the logic funtions for ajax comunication]
  |
  +-Helpers
  | +CSS.php [functions like css_define_id("#sidebar_clock",[widgetname]) os JS wrappers ]
  |
  +-Libraries
  +-Hooks
  |
  +-Views
    |
    +-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:
Code:
class Customers extends Controller {

        function __construct() {
                parent::Controller();
                $this->load->model('customers');
                $this->output->enable_profiler(TRUE);
        }

        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;
             $this->view->('templates/Default/index',$data);
       }

       function AJAX()
       {
              $this->load->model('AJAX');
              $this->ajax->execute_action();  //logic for action or $this->[action]();
      }

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

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

}

Example of a Widget(filename: standard_dialogbox.widget)
Code:
<div id={$css[id]}>
     <B>{$data[title]}</b><BR>
     {$data[data]}
</div>


Example of Template(filename: add.php):


Code:
{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
#2

[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?

Myles




Theme © iAndrew 2016 - Forum software by © MyBB