Cakephp 3.4 JQuery , ajax 和 $_POST

Cakephp 3.4 JQuery , ajax and $_POST

我对 Cakephp 3.4

有个大问题

这是我的控制器:

    //$id=$_POST["idString"]; ---- how can i do this in cakephp?
    $id = $this->request->data('idString');

    $posts = $this->Posts->find('all', array(
        'conditions' => array(
            'Animal_id' => $id
        )
    ));
    $this->set(compact('posts'));

这是我的脚本

$(document).ready(function() {

    $(".dropdown-item").click(function(){
         idString = $(this).attr("value");
        alert(idString);
        $.ajax({
            type: "POST",
            url: "<?php echo  \Cake\Routing\Router::url(array('controller' => 'MyControllerName', 'action' => 'index')); ?>",
            data: "idString="+idString,
            success: function(result){
                $("#show").html(result);
            }
        });

    });
});

这是我的索引:

<?php foreach($posts as $post):?>
    <li><?= $post->title, $post->text; ?></li>
<?php endforeach ?>

<div id="show">
<--show id-->

</div>

我遇到的错误是

已弃用 (16384):Controller::$layout 已弃用。使用 $this->viewBuilder()->setLayout() 代替。 [CORE\src\Controller\Controller.php,第 383 行]

它 returns 我一个 div 2 次。

Cakephp 3.4 在 src/Template/Layout/ajax.ctp 中有 如果没有 $this->fetch('content') ; 如果是则删除或评论。