doujuegai8830 2014-04-10 20:42
浏览 57
已采纳

CakePHP-检索电子邮件模板的名称

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: http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html

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 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
        pr($files);
    

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?