Yii2 - currency format euro - yii2

I have this in config:
'formatter' => [
'dateFormat' => 'yyyy-MM-dd',
'decimalSeparator' => ',',
'thousandSeparator' => '.',
'currencyCode' => 'EUR',
],
This print €20.000,00 but I want 20.000,00€ (with € in end).
Who I do this in yii2?

The main source:
You should set this config:
Yii::$app->formatter->locale = 'et-EE';
With this is enough.

This simply means you need to enable PHP internationalization extension (aka intl) on your server : http://php.net/manual/en/book.intl.php
Read more about \yii\i18n\Formatter::asCurrency() :
This function does not require the PHP intl extension to be installed to work, but it is highly recommended to install it to get good formatting results.
Read more about PHP internationalization extension installation.
For example, to install it on Debian :
sudo apt-get install php5-intl
Don't forget to restart your web server after.

Related

Using logstash Elasticsearch output plugin error: NameError: SSLConnectionSocketFactory not found

I am trying to import data from MySQL to Elasticsearch using logstash version.
Versions of software used:
Java/JRE 1.8
Elasticsearch 6.1.0
Logstash 6.1.0
My conf contents are as follows:
file: simple-out.conf
input {
jdbc {
# MySQL jdbc connection string to our database, mydb
jdbc_connection_string => "jdbc:mysql://valid/validDBNAME?useSSL=false"
# The user we wish to execute our statement as
jdbc_user => "MY USER"
jdbc_password => "MY PWD"
# The path to our downloaded jdbc driver
jdbc_driver_library => "C:\JavaDevelopment\TomcatServer\apache-tomcat-8.5.20\lib\mysql-connector-java-5.1.45-bin.jar"
# The name of the driver class for Postgresql
jdbc_driver_class => "com.mysql.jdbc.Driver"
# our query
statement => "SELECT * from testtable"
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
}
}
output {
stdout { codec => json_lines }
elasticsearch {
hosts => "http://localhost:9200"
index => "test-migrate"
document_type => "data"
}
}
When I run logstash I get the following error:
[2017-12-19T16:50:08,055][ERROR][logstash.pipeline ] Pipeline aborted due to error {:pipeline_id=>"main", :exception=>#<NameError: SSLConnectionSocketFactory not found ERROR
Please suggest how to get past this.
Thanks
Try adding httpclient-VERSION.jar, httpcore-VERSION.jar files to LOGSTASH_HOME/vendor/jruby/lib/ folder.
I had same problem, the solution is:
add LOGSTASH_HOME variable path in environment variables in mycomputer properities to C:\some_path\logstash-6.3.0
then add these files to C:\some_path\logstash-6.3.0\logstash-core\lib\jars
files:
httpclient-4.5.2.jar
log4j-1.2.17.jar
httpcore-VERSION.jar
this is because logstash doesn't come with ssl jar file and you need to add this to jar folder and set the environment so as logstash can read those jar files
and try using gitbash rather than cmd or powershell!
and try to close and restart your logstash and elasticsearch
follow this link to see which index are comming to elasticsearch.
http://localhost:9200/_cat/indices?v
if you are running on diff. port please change port number
addidional tips
and it didn't work for me on jdk 10.x so use jdk 8.x
and maybe installer wont work even so just unzip file and run elasticsearch.bat and logstash -f cong_filepath\configfile.config in bin folders
windows user can type cmd in top of path
Please make sure MySQL is running, (doesn't mean open) on server
Learn # https://www.elastic.co/blog/logstash-jdbc-input-plugin
To resolve it yourself in future:
open logstash/bin folder and right click and gitbash (need git)
type "vi log" and press tab 3 times till all logstahsh files are shown up
a new line will appear, type "vi logstash" and press enter to open source file
you'll have code to understand flow,.. if you look carefully Logstash_home and javacmd (at bottom) are important that execute jar, javacmd should be set to your java_home variable in env variables to jdk8.x and Logstash_home has a path for jar directory, either change it or put you jar to this folder.
Hope this helps!

php 5.x 7.x, ssl pdo error: Peer certificate CN=`someName' did not match expected CN='someIP'

We have a server with mysql on port 3306. We have sertifications and key and we try to connect to this server. But we see such problem:
Peer certificate CN='SomeName' did not match expected CN='someIP'
I've read a lot of articles and can't find answer for PDO PHP. The most interesting is that the SQLYog could connect with all settings.
I've read that I verify_peer_names can be disabled (I hope I understand what is peer_names...), but only if we use openssl_{functions} or mysqli, not PDO. Both options are not appropriate for me. I need PDO.
What I tried to do:
switch between versions of php. It helped me, but I need 5.6 or higher. For php 7.0 the same error.
find another versions of openssl and pdo; fast I understood that its a bad idea :)
find some settings in php.ini, but no settings for my problem, only for creating ssl.
My code for connection:
$dbInfo = array
(
'dsn' => 'mysql:host=123.45.67.890;dbname=someDB;port=3306',
'user' => 'user',
'pass' => 'userpassword'
);
$con = new PDO
(
$dbInfo['dsn'], $dbInfo['user'], $dbInfo['pass'],
array(
PDO::MYSQL_ATTR_SSL_CIPHER => 'AES256-SHA',
PDO::MYSQL_ATTR_SSL_CA => 'SSLCert/ca-cert.pem',
PDO::MYSQL_ATTR_SSL_KEY => 'SSLCert/client-key.pem',
PDO::MYSQL_ATTR_SSL_CERT => 'SSLCert/client-cert.pem',
)
);
echo 'Connection OK!';
We got it working for our internal self-signed certs by not using IP addresses but machine(+domain) names as the CN and connection settings.
So, put 'dbServer1.company.local' as the CN for the server certificate and use the same 'dbServer1.company.local' address as the host part of the DSN for the PDO connection. If you like, you can just use 'dbServer1' but make sure you use it in both places.
This will get you going:
$pdo_options = array(
PDO::MYSQL_ATTR_SSL_KEY => 'path/to/client-key.pem',
PDO::MYSQL_ATTR_SSL_CERT => 'path/to/client-cert.pem',
PDO::MYSQL_ATTR_SSL_CA => 'path/to/ca.pem'
);
PDO::__construct('mysql:host=dbServer1.company.local;dbname=someDB','someUser', 'somePass', $pdo_options);
We manage our own DNS so resolving dbServer1.company.local is not an issue but if your webserver cannot resolve it you or you don't/can't manage the DNS entry, then hack in something like the following to your etc/hosts file:
10.5.5.20 dbServer1.company.local
or
10.5.5.20 dbServer1

Predis configuration in Laravel 5.2

I am confused about the Predis setup (PHP client for Redis) in this case in a Laravel 5.2 project.
The documentation says you need to autoload it into composer to use it in the entire app without loading it on each page...
HOW? WHERE? WHAT? do I need to add or write to do this? I can't seem to figure it out as I know very little about installation en server configuration..
This is what I mean. This needs to go somewhere I assume
require 'Predis/Autoloader.php';
Predis\Autoloader::register();
Thx
Another method
Download predis package from https://github.com/nrk/predis
Extract it
Copy the contents of folder into Laravel/vendor/predis/predis. Then folder structure will be
In Controller
class WelcomeController extends Controller
{
public function index()
{
$client = new \Predis\Client([
'scheme' => 'tcp',
'host' => '127.0.0.1',
'port' => 6379
]);
$client->set('foo', 'bar');
return $value = $client->get('foo');
}
}
If redis is installed in your system, it will return value of 'bar'
Please, read documentation careful:
Autoloading is handled automatically when dependencies are managed through Composer, but it is also possible to leverage its own autoloader in projects or scripts not having any autoload facility:
// Prepend a base path if Predis is not available in your "include_path".
require 'Predis/Autoloader.php';
Predis\Autoloader::register();
By default Laravel uses Composer to install dependencies, so you do not need to do anything special. Just add predis/predis as usual to your deps in composer.json. Read more using of composer here.

How to change database of yii2 advanced template

How can i change the database information of my yii2 advanced template?
i cant find the database settings.
http://www.yiiframework.com/doc-2.0/guide-index.html
In /common/config/main-local.php you set your database settings:
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=DATABASE_NAME',
'username' => 'DATABASE_USER',
'password' => 'DATABASE_PASSWORD',
'charset' => 'utf8',
],
The installation guide for advanced template is here: https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/start-installation.md
The advanced template has environments that each define the target specific configuration. Basically after cloning the template you need to make sure you setup the files under the environments-folder correctly (it comes with dev and prod predefined configurations - for development and production environments).
In the config subfolders you'll find the *-local.php files that indicate configuration specific to that environment.
For the database you have to look in common/config/main-local.php.
After you're done with that, just navigate back to the templates' root folder and run ./init. It will ask you which environment you want and put the files in place. Switching to another environment is just an ./init call away.
Obviously you're not obligated to keep on using the environments if you don't have use for it, you might as well modify the /common/config/main.php file and add the connection info there. But given that the advanced template assumes multiple deployment stages for your application it is a very good setup.

Yii2 Gii : You are not allowed to access this page

I'm using Yii2 advance template and I can access gii tool successfully in my local machine.
But when I upload it into real server, there is a message "You are not allowed to access this page."
Could you tell me which file should I have to config and could you print screen or paste the whole content of that config file?
Thanks you before hand.
You should simply add your IP address in gii config :
'gii' => [
'class' => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1', '::1'] // adjust this to your needs
],
http://www.yiiframework.com/doc-2.0/guide-start-gii.html
EDIT : in advanced app, gii conf is in
environments/dev/backend/config/main-local.php
environments/dev/frontend/config/main-local.php