是否可以在bootstrap模式中显示视图(例如add.ctp)?如果是这样,可以在不加载默认布局的情况下仅在add.ctp文件中渲染HTML?
因为目前我正在尝试构建类似于add.ctp文件中的自定义表单,以便在模式中显示它,并且它确实是一种痛苦,试图发布并获取JSON对象以提交形成并填充我的应用程序中的网格。
是的。
在Ajax文件夹中创建add.ctp,例如:
/Posts
index.ctp
/Ajax
add.ctp
在帖子中:: add()设置ajax布局,并使用JS get/post/add and Modal。
阅读:
https://book.cakephp.org/3.0/en/controllers/components/request andling.htmlhttps://book.cakephp.org/3.0/en/views.html#layouts
编辑:
在控制器中
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
编辑2(jQuery part)示例
<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"));
});