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.
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/
Related
I need to change
logo_url
for transactional emails with external link, for example
https://exampledomainname.com/image.png
but I can't hardcode all or even one file in
app/locale
Is there any way to add external url as logo_url? As when I go here:
System > Configuration > General > Design > Transactional Emails
I can only add image to hosting area
As far as I was looking into the web there is no best practice way to directly rewrite logo_url, but we can create custom variable and then use it into email templates. We can do it manually from admin or using programming way. My requirements is to implement this in programming way, so we start with shell script(shell\external_logo_url.php) to create custom variable:
<?php
require_once '../abstract.php';
class External_Logo_Url extends Mage_Shell_Abstract
{
public function run()
{
$variable = Mage::getModel('core/variable')
->setCode('variable-code')
->setName('variable-name')
->setPlainValue('variable-value')
->save();
}
}
$shell = new External_Logo_Url();
$shell->run();
Also we need to change template files in app\locale, so you need replace all template files or custom templates that you need. You should look for {{var logo_url}} and replace with {{customVar code=variable-code}}.
I want to bulk upload users in the moodle plugin face-to-face, using .csv.
The user upload has to take place in the session and be made by admin or manager.
Using the file picker element from the File API
$mform->addElement('filepicker', 'userfile', get_string('file'), null,
array('maxbytes' => $maxbytes, 'accepted_types' => '*'));
Then I need to extract this data and show the names, emails etc. in the attendees list and then in reports. Is fgetcsv the right choise?:
$fields=fgetcsv($filehandle,0,$this->config->delimiter);
var_dump($fields)
$data=array();
while($row=fgetcsv($filehandle,0,$this->config->delimiter))
{
$data_row->startdate=$row[0]
$data_row->enddate=$row[0]
$data_row->room=$row[0]
$data_row->status=$row[0]
$data_row->firstname=$row[0]
$data_row->lastname=$row[0]
$data_row->username=$row[0]
$data_row->useremail=$row[0]
$data_row->attendance=$row[0]
$data_row->signupdate=$row[0]
array_push($data,$data_row)
$DB->insert_record('facetoface',$data_row, false);
}
There isn't a plugin with user upload function in face-to-face sessions, nor there is something similar.
Where to place the right code lines (in the different files of the plugin), or better said, which is the right way to proceed?
I would preffer to make a custom plugin, if that is easier,just need a guidence for the structure of it. The functionality is still similar to face-to-face, the sessions atendees are just uploaded.
There is an option to bulk upload users in Totara.
https://github.com/totara/seedlings/tree/totara-seedlings-2.7/mod/facetoface
But for your plugin you might want to use the csv_import_reader class
For an example have a look at /admin/tool/uploaduser/index.php
I have spent hours searching to find where magento stores full county name.
We can get a full list of countries using this code:
$_countries = Mage::getResourceModel('directory/country_collection')
->loadData()
->toOptionArray(false);
This will return an array with country code and name, I investigated the directory module, and found out this call gets data from the table
directory_county
But this table don't have full county name! So where is it stored?
and how is it retrieved using that call?
Thanks in advance.
Ok so to compensate for my wrong answer. Here is how this works:
/lib/Zend/Locale/Data/en.xml - if your store is in english, else another xml in the same directoery is read. Every country is there and its code under the xml tag <territory>
The xml is cached using the Zend_Cache_Core class.
/lib/Zend/Locale.php - function getTranslation invokes the lib/Zend/Cache/Core.php class
to load from the cache.
Example: If you change the name of some country in en.xml and clear the magento cache. You will see the change when u invoke your code again.
Full country names are not stored in database. Magento uses inbuilt Zend functionality.
Check file: lib/Zend/Locale/Data/Translation.php for full list.
Use the Zend_Local translation.
<?php
$code = 'EN';
echo Mage::app()->getLocale()->getTranslation($code, 'Territory', null, 2);
?>
Use the column 'iso2_code' from the table 'directory_country' for your $code.
Magneto only stores country codes in DB, and relies for names on Zend's Locale module to provide translated names, for different locale.
By the toOptionArray method it invokes the Zend_Locale class to get the translated value.
Refer $name = Mage::app()->getLocale()->getCountryTranslation($data['value']);, which gets to Mage_Core_Model_Locale and then to Zend_Locale.
It decides which of the node from the data to read, by the switch case statement in Zend_Locale_Data::getContent() line# 962, 963
Magento caches the names, so if you make any change to XML files, make sure to clean your cache folder to get what you seek.
I have a wordpress blog. I created a db table which stores dictionary information and I want to publish this data from a URL . (For ex: "myblogaddress.com/mytest.php")
I have been researching for 2 days but nothing works I tried.
In my page; I use the php code shown in blow.
<?php
global $wpdb;
$words = $wpdb->get_results("SELECT * FROM $wpdb->words")
echo $words[0]->ENG;
?>
I wonder that;
- Which directory does my php page to be into ?
- What I need to do (other config, permission etc.) to do what I want.
Regards.
If you're loading it from a standalone PHP file (ie not from within your WordPress theme), you'll have to call wp-load.php to initialise the WordPress variables (including $wpdb). Have a look at this answer, including the comment about only needing wp-load.php.
I'd consider using a relative path (what that would be would depend on where you put your page relative to WordPress) rather than using $_SERVER['DOCUMENT_ROOT'];, but that's just a personal preference.
EDIT
Rereading after seeing your comment, I've just realised $wpdb->words probably won't exist. Try
$words = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "words")
instead. That'll generate the table name correctly as wp_words. Of course, you'll need to populate it the same way.
What I am looking for is something where I can easily change the text on a page. I want to set it to a default value and if something is present for a specific page to change it
So it would say something like:
I like stackoverflow
But if the value of website was "reddit" it would instead say
I like reddit
So stackoverlflow would be the default, reddit would be something that is set to overwrite it.
edit:added comment
Scenario I: Domain Name based data handling
If you want to work on the basis of domain, then in Zend Framework you can work with customize routers.
Scenario II: GET/POST based input handling
Otherwise if you want to display on the basis of GET or POST input you can place something default value as
$myDynamicVar = $this->getRequest()->getParam('some_key', 'default-value');
Scenario III: subdomain based input handling
Again you will need to have your custom router for the purpose, in addition to having support of wildcard subdomain names with your hosting provider
In a definitions file:
<?php
/* site.php
* customize this file
*/
class Site
{
static public $name = "stackoverflow";
}
?>
In your page file:
<?php
/* page.php */
include_once 'site.php';
echo "I like {Site::$name}";
?>