2014-04-10 20:42 阅读 48


I'm building a CakePHP application, and I'm trying to allow users to pick an email template from a list and then send it to the addresses that they choose. I'd like to avoid hard-coding the names of the templates, as they are likely to change and be updated over time. How can I generate a list (in my controller) of the filenames of all the email templates I have? I've tried accessing the contents of app/view/Emails/text using the CakePHP Folder class as described here:

However, that didn't work; I'm unable to get the contents of that directory. I just need to access the filenames; I can do the rest of the logic once I get them.

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

1条回答 默认 最新

  • 已采纳
    douqiang5163 douqiang5163 2014-04-10 21:52

    Try this in any method in your controller:

        App::uses('Folder', 'Utility');
        $dir = new Folder(APP . 'View/Emails/text/');
        $files = $dir->find('.*\.ctp');
        //print the array to inspect

    It should show you all the .ctp template files in /app/View/Emails/text/

    点赞 评论 复制链接分享