New to HMVC in Codeigniter.
Dynamic form allows new "segments" to be created when a user clicks a link.
Currently the segment html & php is in module/view/segment_view.php. The view requires dy开发者_开发百科namic php variables as well.
How can I "load the view" using jQuery? I understand I can't directly load a view from jQuery but am lost on how to structure the controller for an AJAX call. Seems this may not be a strength of Codeigniter?
EDIT:
The "segment" is inside a form. The form always has 1 segment. jQuery can add more segments. Each segment requires php arrays for form inputs and validation.Here is a pared down version of the form_view file
for ($i=1; $i<=$number_of_segments; $i++) {
$data['location'] = array(
'name' => "segment[$i][location]",
'value' => set_value("segment[$i][location]"),
'maxlength' => '255',
'size' => '30'
);
?>
<div class="area">
<div class="row"><h2>Segment <?php echo $i;?></h2></div>
<?php
$this->load->view('module/segment_view', $data);
?>
</div> <!--/div class="area"-->
<?php
} //end for
?>
OK, so this isn't really separating application logic from presentation, now is it? Ha ha. So what is the best way to structure this so the code is HMVC and can be accessed from a php controller/view as well as jQuery?
You can't call view files directly by URL, you need to call a controller method that loads the view.
If you want to do some "ajax only" stuff, you may use this function:
if ($this->input->is_ajax_request()) // Do ajax stuff
Examples would be loading view fragments or json. You don't have to make "ajax only" methods in your controller, you can use this function from within your existing controller methods to do something different if it's an ajax request.
Not sure if this resolves anything for you, provide some code and more context of what you're trying to do and we can give you some clearer advice.
精彩评论