I want to fill $data array with some values (index action) and to use that array (sender action) to create a JSON object. I want to use that JSON object in index.ctp (jQuery). I tried using the code below but it's not working, I don't receive any data (jsonArr). I think the problem should be on PostsController but I just can't find a solution.
PostsController:
<?php 
class PostsController extends AppController {
    public $data = array();
    public function index()
    {
         $this->layout = 'default';
        this->data[] = array
        (
            array(
                "id" => "1",
                "title" => "title1",
                "author" => "author1"
            ),
            array(
                "id" => "2",
                "title" => "title2",
                "author" => "author2"
            ),
            array(
                "id" => "3",
                "title" => "title3",
                "author" => "author3"
            )
        );
    }
    public function sender()
    {
         $this->layout = 'default';
        foreach ($this->data as $i) {
          foreach ($i as $item) {
               $all[] = array(
                "id" => $item['id'],
                "title" => $item['title'],
                "author" => $item['author']
                );
            }
        }
        $this->set("json",json_encode($all));
    }
}
?>
index.ctp
<div>
Content  
</div>
<div>
Content
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript"> 
var jsonArr = [];
$.getJSON(plgFcRoot + "posts/sender", function(data) {
                  $.each(data, function(key, val) {
                          jsonArr.push({
                            id : val.id,
                            title : val.title,
                            author: val.author
                          })
                  });
 });
    console.log(jsonArr);
</script>
sender.ctp
<?php
echo $json;
?>
 
    