How can we use PHPMailer instead of Tmail in agile toolkit?
something like this:
$phpmailer=$this->add("phpmailer");
$phpmailer->functions...
Thanks
add atk4-addons
add phpmailer lib
git submodule add https://github.com/PHPMailer/PHPMailer.git .
setup mail to use PHPMailer class
$mail = $this->add("TMail");
$mail->addTransport("PHPMailer");
update your config.php, e.g.
$config["tmail"]["from"] = "info#bla.com";
$config["tmail"]["smtp"]["host"] = "ip";
$config["tmail"]["smtp"]["port"] = "25";
$config["tmail"]["phpmailer"]["reply_to"] = "info#bla.com";
$config["tmail"]["phpmailer"]["reply_to_name"] = "bla";
$config["tmail"]["phpmailer"]["from"] = "info#bla.com";
$config["tmail"]["phpmailer"]["from_name"] = "bla";
$config["tmail"]["phpmailer"]["bcc"] = "support#bla.com";
$config["tmail"]["phpmailer"]["bcc_name"] = "bla";
Like any other 3rd part library.
require 'path/to/class.phpmailer.php';
$mail = new PHPMailer;
You can use
$this->api->pm->base_directory
to start path from base directory of project.
require $this->api->pm->base_directory.'path/to/class.phpmailer.php';
$mail = new PHPMailer;
https://github.com/atk4/atk4/blob/master/lib/PageManager.php#L73
You can actually configure TMail to use PHPMailer for delivering your messages:
https://github.com/atk4/atk4-addons/blob/master/misc/lib/TMail/Transport/PHPMailer.php
Related
In my .env file there is something like this:
GOOGLE_MAP_API=AIzaSyByfXuuwxOIaWlefhSxqhMweF-0
Another_API_KEY=5893978af2537e042beb233b1
I would like to create a .env file in which "Another_API_KEY" is randomly choosen from multiple api keys list.
Something like this:
GOOGLE_MAP_API=AIzaSyByfXuuwxOIaWlefhSxqhMweF-0
var r_text = new Array();
r_text[0] = "a3219d4e2772db6e34c62144b27f";
r_text[1] = "5bbe61fe6db548e665a49663eba2";
r_text[2] = "d74ae61790a9937e3f6d5d3ddc83";
var nn = Math.floor(3 * Math.random());
var Another_API_KEY = r_text[nn]
But this is'n working. Is this possible to get random keys from the list to React JS Application from .env file?
.env files store strings so it's not possible to run Javascript inside it.
What you can do, however, is store all keys you want to randomly pick up from in .env and, when you use them inside your app, you pick one of them.
.env
GOOGLE_MAP_API=AIzaSyByfXuuwxOIaWlefhSxqhMweF-0
RANDOM_KEYS="a3219d4e2772db6e34c62144b27f 5bbe61fe6db548e665a49663eba2 d74ae61790a9937e3f6d5d3ddc83"
Then on your code:
// Choose random key from all options
const RANDOM_KEYS_ARRAY = process.env.RANDOM_KEYS.split(" ")
const RANDOM_KEY = RANDOM_KEYS_ARRAY[Math.floor(RANDOM_KEYS_ARRAY.length * Math.random())]
Here's a sandbox with working code:
https://codesandbox.io/s/getting-random-key-from-env-xuup4r
I managed it.
I the file app.js where the command was to get api key from .env: &appid=${process.env.REACT_API_KEY}
I deleted: process.env.
and inserted
'var r_text = new Array();
r_text[0] = "456afa82537e042beb233b25";
r_text[1] = "s54667e042b33b1fa525";
r_text[2] = "456a82537e042beb233b525";
var nn = Math.floor(3 * Math.random());
var REACT_API_KEY = r_text[nn];'
And it works. Thank you
$user= $this->Users->newEntity();
I want to create a folder for every registered user
example if new user input michael
how to achieve this and will create a directory /img/users/michael/
$dir = new Folder(WWW_ROOT.'img'.DS.'users'.$user->username);
$path_data = $dir->create($dir);
Error: Cannot use object of type Cake\Filesystem\Folder as array
Create directory PATH will in in create() method
$dir = new Folder(WWW_ROOT.'img'.DS.'users'.$user->username);
$path_data = $dir->create($dir);
should be
$dir = new Folder();
$path_data = $dir->create(WWW_ROOT.'img'.DS.'users'.$user->username);
Details Here
Update
There is a directory separator missing. it should like
$dir = new Folder();
$path_data = $dir->create(WWW_ROOT.'img'.DS.'users'.DS.$user->username);
Thanks #ndm
I'm using Location module (particularly its Location CCK part) with Drupal 7. Added location field 'field_location' to User (as an example of hosting entity), and initialized location values for test users in user edit interface. However, I'm unable to access location data of the current user:
global $user;
$user_id = $user->uid;
$loc = $user->field_location;
or:
$wrapper = entity_metadata_wrapper('user', $user_id);
$loc = $wrapper->field_location;
The statements with $loc don't work for object and wrapper (while both user object and wrapper are initialized successfully). Same for:
$loc = $wrapper->field_location[0];
$loc = $wrapper->field_location->raw();
I've read a number of posts on this topic, however haven't found a workable solution, would appreciate insights on this.
The location module, by itself, does not support the Entity API/Metadata Wrapper out-of-box. However, it is packaged with the Location Entity module, which will enable it for entity api support.
Once enabled,
$wrapper = entity_metadata_wrapper('user', $user_id);
$loc = $wrapper->field_location->value();
Works as expected.
If you want a quick workaround, you can also do:
$user_wrapper = entity_metadata_wrapper('user', $user_id);
$raw_user = $user_wrapper->raw();
$loc = $raw_user->field_location['und'][0];
This isn't elegant, but it's a solution without additional modules. Take your pick.
I'm trying to create a new node for every file thats in a specific folder using Drupal 7.
A good example of what I'm trying to create is Youtube.
When I paste a video with the .mp4 extension in a specific folder, I want Drupal to scan that folder (I will tell Drupal when to scan, so this doesn't have to happen automatically), and create a node with that video in it. I will manually set the title, description, etc... myself using the admin interface, and publish it.
I know my way around in Drupal, and its modules, but I'm not an expert. I've been googling for awhile now and the only thing I could find was:
file_scan_directory($dir, $mask, $options = array(), $depth = 0)
I'm not asking for a complete copy/paste solution, I was just hoping someone could give me some tips, useful links or tutorials on how to do this.
To create a node for each video file you find in a directory, you can use code similar to the following one.
foreach (file_scan_directory($dir, '*.mp4', array('recurse' => FALSE) as $uri => $info) {
$body_text = 'Build the body text.';
$node = new stdClass();
$node->type = $node_type;
node_object_prepare($node);
$node->title = 'Node Created Programmatically on ' . date('c');
$node->language = LANGUAGE_NONE;
$node->body[$node->language][0]['value'] = $body_text;
$node->body[$node->language][0]['summary'] = text_summary($body_text);
$node->body[$node->language][0]['format'] = 'full_html';
node_save($node);
}
How do you get the database name from Magento?
I have seen functions like the one below that can get the table name.
$orderItemTable = Mage::getSingleton('core/resource')->getTableName('sales/order_item');
I was hoping that there was some sort of function like this:
Mage::getSingleton('core/resource')->getDatabaseName();
Thanks in advance for any ideas.
Each module can specify it's own connection so you are right to go via a model.
$config = Mage::getResourceModel('sales/order')->getConnection()->getConfig();
// $config is an array
$dbname = $config['dbname'];
If you're only interested in the default a slightly more efficient way might be:
$dbname = (string)Mage::getConfig()->getNode('global/resources/default_setup/connection/dbname');
To get the db name try
Mage::getConfig()->getResourceConnectionConfig('default_setup')->dbname;
See How to get magento database details
It is always possible to get the current connection from Mage::getSingleton('core/resource')->getConnection('core_write'), quite specially if you use only one database.
$configArray = Mage::getSingleton('core/resource')->getConnection('core_write')->getConfig();
$db = $configArray['name'];
But it's comming with a zend adapter Zend_Config
// Create the object-oriented wrapper upon the configuration data
$config = new Zend_Config($configArray);
$db = $config->get('dbname');