I'm currently working with Yii2 framework and I need to set the default decimal separator symbol ',' instead of '.'. Searching on the internet I find this solution that doesn't work:
'formatter' => [
'class' => 'yii\i18n\Formatter',
'thousandSeparator' => '.',
'decimalSeparator' => ','
],
I put those lines in the web.php file in the 'components' section.
Do you have any further suggestion?
Your settings look fine. You just have to make sure your output is handled by the Formatter. Like this... (try in your code)
echo Yii::$app->formatter->asDecimal(1234567.12); // => 1.234.567,12
The Yii-framework format variables by using such methods "behind the scenes".
Related
I have the following perl code in where I have a perl structure as follows:
`
use Data::Dumper;
my %data = (
'status' => 200,
'message' => '',
'response' => {
'name' => 'John Smith',
'id' => '1abc579',
'ibge' => '3304557',
'uf' => 'XY',
'status' => bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' )
}
);
my $resp = $data{'status'};
print "Response is $resp \n";
print Dumper(%data->{'response'});
Getting the status field works, however If I try something like this:
my $resp = $data{'response'}
I get Response is HASH(0x8b6640)
So I'm wondering if there's a way I can extract all the data of the 'response' field on the same way I can do it for 'status' without getting that HASH...
I've tried all sort of combinations when accessing the data, however I'm still getting the HASH back when I try to get the content of 'response'
$data{'response'} is the correct way to access that field on a hash called %data. It's returning a hash reference, which prints out by default in the (relatively unhelpful) HASH(0x8b6640) syntax you've seen. But if you pass that reference to Dumper, it'll show you everything.
print Dumper($data{'response'});
to actually access those subfields, you need to dereference, which is done with an indirection -> operation.
print $data{'response'}->{'name'}
The first access doesn't need the -> because you're accessing a field on a hash variable (i.e. a variable with the % sigil). The second one does because you're dereferencing a reference, which, at least in spirit, has the $ sigil like other scalars.
Thanks for your posts. I fixed the code as follows:
use Data::Dumper;
my %data = (
'status' => 200,
'message' => '',
'response' => {
'name' => 'John Smith',
'id' => '1abc579',
'ibge' => '3304557',
'uf' => 'XY',
'status' => bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' )
}
);
my $resp = $data{'response'};
print Dumper($resp);
Now it works like a charm, and I'm able to get the data I want.
Does anyone know why I get a parsing error with the following code?
'always_load' => array(
array('auth');
array(
array('auth' => PKGPATH.'auth/')
);
'packages' => array(
'orm',
),
A config file is one long nested or multi-dimensional array, so you never use semi-colon's, only comma's. This is standard PHP array notation.
I'm a newbie using cakephp-3.0.
I'm planing to show different templates-views according to user's browser/agent.
In cakephp2.x the code can be like below:
if ($this->DisplayModeService->hasSpViewSupport()) {
App::build([
'View' => [APP . 'View/SmartPhone/', APP . 'View/'],
]);
}
but in cakephp3.0 it's in app.php :
return [
'App' => [
'paths' => [
'templates' => [
APP . 'Template' . DS . 'SmartPhone' . DS,
APP . 'Template' . DS,
],
],
],
];
But I want to change the template route only if the page has smartPhone version.
In the case above it jump into SP version anyway.
(for I wanna keep the same name for the same page )
ex:
/Template/SmartPhone/profile.ctp, /Template/profile.ctp.(has SP/PC Version)
/Template/news.ctp (PC Version only)
can it be possible?
You would better use $this->request->is('mobile'), and Themes
in ZF2 skeleton, router configuration uses a key :
'__NAMESPACE__'
precisely :
'__NAMESPACE__' => 'Application\Controller',
cf:
https://github.com/zendframework/ZendSkeletonApplication/blob/master/module/Application/config/module.config.php#l32
We tried in our modules router config to use without quote:
__NAMESPACE__ => 'Application\Controller',
but it seems to break configuration.
why do we use quote instead of
__NAMESPACE__
to get its value ?
because by default, config files hasn't namespace declared. Config parser can read string
'__NAMESPACE__'
and determine correctly the namespace.
If you want to use it without quotes, you can declare in your config file :
namespace Application;
and use __NAMESPACE__ without quote.
That's why you can see sometimes in tutorials for Doctrine config's sample like :
'doctrine' => array(
'driver' => array(
'application_entity' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'paths' => __DIR__ . '/../src/' . __NAMESPACE__ . '/Entity',
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => 'application_entity',
)
)
)
),
I have a CakePHP app that is being moved to Sql Server from MySql. There is one query that does not seem to transfer correctly:
$this->Model->find('all', array(
'conditions' => array(
'Model.column' => array(1, 2, 3)
)
)
);
When I use this syntax with mysql, it seems to 'unpack' the array
correctly, and the query generated is something like
"...WHERE 'Model.column' IN (1, 2, 3)..."
When I use sql server, the query generated is
"...WHERE 'Model.column' IN 'Array'"...
which obviously generates an error. I posted this question on the CakePHP Google Group yesterday, but have not received a reponse, so I thought I would try SO. If anyone has any ideas/suggestions I would appreciate it.
The code that generates this is in dbo_source.php (function conditionKeysToString) and while specific database drivers can override this, I have never seen that done.
I have 1.2.5, 1.2.6 and 1.3.0-RC1 on my system and they all append ' IN (' and nothing overides that function. There is no instance of just appending ' IN ' and then deciding if it is an array or scalar value. The word Array is what happens when an array variable is evaluated in a string context. EG: php -r '$a = array(1,2,3); echo $a;' will output Array.
Check the cake/VERSION.txt file in both. If they are different, back up the cake directory on the SQL Server instance and replace it with the one from MySQL.
If they are the same try going to the cake/libs/model/datasources directory. Hopefully you have Unix or Linux because "grep -r ' IN ' *" will help you out immensely. Otherwise compare dbo_soures.php and dbo/dbo_mssql.php between both installs of cake and see if there are any differences in conditionKeysToString.
Ultimately I would upgrade to 1.2.6 just so that you get any and all fixes.
Try passing that condition as a string:
$this->Model->find('all', array(
'conditions' => array(
'Model.column in (1, 2, 3)'
)
)
);
Try it like this:
$this->Model->find('all', array(
'conditions' => array(
'Model.column' => array(
'OR' => array(1, 2, 3)
)
)
)
);