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',
)
)
)
),
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.
I am trying to integrate an API into my Wordpress plugin. The following PHP code successfully connects to the API and retrieves a list of Estates (the API is from a real-estate software):
$url = 'https://api.whise.eu/v1/estates/list';
$body = array(
'Filter' => array( 'languageId' => 'nl-BE'),
);
$args = array(
'headers' => array( 'Authorization' => 'Bearer ' . $token),
'body' => json_decode($body)
);
$response = wp_remote_post($url,$args);
As per the documentation (http://api.whise.eu/WebsiteDesigner.html#operation/Estates_GetEstates) it is possible to filter the results, but I haven't been able to get this to work. I don't have much experience with APIs and JSON, so I might be missing something here.
The code above still retrieves the data in English, even though I added the language filter as explained in the docs. When I replace 'body' => json_decode($body) with 'body' => $body, I get the following response:
{"Message":"The request entity's media type 'application/x-www-form-urlencoded' is not supported for this resource."}
Thanks!
Just so that this question doesn't go unanswered:
You need to add the Content-Type header and set it to application/json. This is so the endpoint can interpret your data as a JSON string.
You also need to change 'body' => json_decode($body) to 'body' => json_encode($body) as you want to convert your $body array into a JSON string (see json_decode() vs json_encode()).
This is how your code should look now:
$url = 'https://api.whise.eu/v1/estates/list';
$body = array(
'Filter' => array( 'languageId' => 'nl-BE'),
);
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $token,
'Content-Type' => 'application/json'
),
'body' => json_encode($body)
);
$response = wp_remote_post($url,$args);
I have written a custom related vacancies query for my site, using the plugin WP Job Manager. When using query monitor, I keep getting that the query is very slow (5+ seconds).
I've implemented query caching, except this requires the query to run at least 1 time.
Is it possible to speed up a query like this even more?
$location = get_post_meta($id, '_job_location', true);
$category = get_post_meta($id, 'job_category_wo', true);
$args = array(
'post_type' => 'job_listing',
'numberposts' => 5,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => '_job_location',
'value' => $location,
'compare' => '='
),
array(
'relation' => 'AND',
array(
'key' => '_job_location',
'value' => $location,
'compare' => '='
),
array(
'key' => 'job_category_wo',
'value' => $category[0],
'compare' => 'LIKE'
)
)
)
);
$postslist = get_posts( $args );
In the example you show, you search for posts matching this condition:
_job_location = $region OR _job_location = $region AND job_category_wo LIKE $category[0]
You can simplify this expression to:
_job_location = $region
Boolean algebra says (A) OR (A AND B) is redundant. It's the same as simply (A).
This would factor out the OR operation, which is hard for SQL to optimize.
P.S.: I think there are other mistakes in your example. You set a variable $location but later you use $region. Which is it?
Also you are not sanitizing any values to prevent SQL injection.
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".
I have following code:
<?php
$select_options = array();
foreach($delivery_options as $option)
{
$select_options[$option->getDeviceId()] = $option->getDeviceName();
echo $select_options[$option->getDeviceId()];
}
echo $this->Form->input('default_device', array(
'type' => 'select',
'options' => $select_options,
'value' => $default_device,
'label' => '',
));
?>
In foreach loop every echo returns this:
abc'abc
In html source code it looks like this abc'abc
and then in select input: abc'abc
In html source code: abc'abc
It means that & char from abc'abc was converted to it's html encoding - & - but how did it happen?
I also tried htmlentities() and htmlspecialchars() but this still doesnt help...
The select input type allows for a special $option attribute called
'escape' which accepts a bool and determines whether to HTML entity
encode the contents of the select options. Defaults to true.
Try setting it to false.
echo $this->Form->input('default_device', array(
'type' => 'select',
'options' => $select_options,
'escape' => false, // like so
'value' => $default_device,
'label' => '',
));