2016-11-29 12:49 浏览 17

CakePHP 3查看变量

my question is give it a way to parse a view file (.ctp) into a variable ? I want to create a ajax function that gives a ctp file or better says the content of this back. The call from the javascript to cakephp's controller work but now i doesnt now how i can get my specified ctp file in the template folder parse it into a variable and send it back to the javascript function.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答 默认 最新

  • 已采纳
    dongying7667 dongying7667 2016-11-29 13:05

    Lets say, you are using the controller sites and the view is index.

    public function index() {
        if($this->request->is('ajax') {
            // prepare output for ajax. best way to do is to prevent styled output

    In your TestView/index.ctp you can now prepare your output for ajax and just call the controller/action URL by AJAX:

        url: "/sites/index",
        success: function(reponse) {
            console.log(response); // here comes the output from /sites/index
    点赞 评论 复制链接分享