Issue
Is it possible to display a view (add.ctp for example) in a bootstrap modal? And if so is it possible to render only the html in the add.ctp file without loading the default layout?
Because currently I am trying to build a custom form similar to the one in the add.ctp file in order to display it in the modal, and its really a pain trying to post and get the json objects in order to submit the form and populate the grids in my application.
Solution
Yes it`s possible.
Create add.ctp in Ajax folder, for example:
/Posts
index.ctp
/Ajax
add.ctp
in Postings::add() set Ajax layout and with js get /posts/add and render modal.
Read:
https://book.cakephp.org/3.0/en/controllers/components/request-handling.html https://book.cakephp.org/3.0/en/views.html#layouts
EDIT:
in Controller
public function add()
{
// your code here ...
if ($this->getRequest()->is('ajax')) {
// render "add" view in Ajax folder and use "ajax" Layout
$this->render('Ajax/add', 'ajax')
}
}
https://book.cakephp.org/3.0/en/controllers.html#rendering-a-specific-template
EDIT 2 (jQuery part) example
<button type="button" data-toggle="modal" data-remote="<= $this->Url->build(/* ADD HERE YOUR PARAMS*/)
?>" data-target="#myModel">Open Model</button>
$('body').on('click', '[data-toggle="modal"]', function(){
$($(this).data("target")+' .modal-body').load($(this).data("remote"));
});
Answered By - Salines
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.