Question

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.

Was it helpful?

Solution

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/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top