Orchestra parser signature - xml-parsing

I need to update some xml persers which uses Orchestra/parser for Laravel. So I need to find out how it works. On package page there is no documentation. If you have some give the link please. Cause there are signatures like
$dataPrinters = $xml->parse([
'printer' => ['uses' => 'printer[id,title,small_img,large_img]']
]);
Can somebody tell me please what means this signature? What exactly means that array literal in string. It looks weird. Thanks a lot.

So I have it. The signature 'printer' => ['uses' => 'printer[id,title,small_img,large_img]'] means that if the xml looks like
<root>
<printer>
<id>1</id><title>xxxx</title>...
</printer>
<printer>
<id>2</id><title>yyyyyy</title>...
</printer>
</root>
it create the array like
[
printer => [
['id' => 1, 'title' => 'xxxx' ...],
['id' => 2, 'title' => 'yyyyyy' ....]
]
]

Related

Yii2 does not create nice url - parameter

I use the URL manager in Yii2 to create nice urls, which works, as long as there are no parameters on the url.
I set up the following config:
urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
Using
Url::to(array('crtl/action', 'paramx' => 'computer:net', 'paramy' => 'abc')) results in the following url:
http://localhost/crtl/action?paramx=computer:net&paramy=abc
But what I need is the following:
http://localhost/crtl/action/paramx/computer:net/paramy/abc
How can I prettify the url paramters to?
If your argument is number then rule of URL manager will be:
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>'
If your argument is text then rule of URL manager will be:
'<controller:\w+>/<action:\w+>/<name:\w+>' => '<controller>/<action>'
In case we declare pretty url, if we need result followed by '/' then we also need to define url rules for routing
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:\w+>/<action:\w+>/<id:\w+>/<ids:\w+>' => '<controller>/<action>',
],
],
So we can call this routing as :
<a href="<?php echo \yii\helpers\Url::base(true)."/site/testing/5/8"?>">
<a href="<?php echo \yii\helpers\Url::to(['site/testing','paramx'=>'x1','paramy'=>'y1'])?>">
In first case we had created the url as we want.
In second case we had used url:to for routing as we can see we had provided paramX and param y in parameter.
For both of this,the result will be,
public function actionTesting() {
print_r(Yii::$app->request->getQueryParams());
die();
}//will get the query params that we had sent
Output will be:Array ( [paramx] => x1 [paramy] => y1 ) ;
As the case you are asking is not the url routing pattern for yii2,this is the preferred way for yii2

CakePHP 3 routing dynamic url

I have an eCommerce website and need to create some custom URLs. These URLs will be generated dynamically. The structure will be
Example URL: http://website.com/categoryname/product-title
Here the category name is dynamic. It will change for each product, it can be
website.com/buttons/CP1 or
website.com/ribbons/red so on
In any case these URLs should be redirected to http://website.com/products/productdetail/product-title
I tried the following script:
$routes->connect(
'/:type/:slug/*',
['controller' => 'Products','action' => 'productDetail'],
['type' => '\b(?:(?!admin)\w)+\b'],
[
'slug' => '[A-Za-z-]+',
'pass' => [
'slug'
]
]
);
['type' => '\b(?:(?!admin)\w)+\b'] is to exclude the other controllers. In this case 'Admin'. This works but the parameters passed through the URL (product-title) is not getting in the controller function(productDetail)
Any help will be appreciated.
It is fixed. Updated script below.
$routes->connect(
'/:type/:slug/*',
['controller' => 'Products','action' => 'productDetail'],
[
'type' => '\b(?:(?!admin)\w)+\b',
'pass' => ['slug']
]);
According to the API the connect() function only accepts 3 parameters and you are actually passing 4. See Cake Routing Router - Connect
I have not tested this at all, but I think you should re-write it like this:
$routes->connect(
'/:type/:slug/*',
['controller' => 'Products','action' => 'productDetail'],
[
'type' => '\b(?:(?!admin)\w)+\b',
'slug' => '[A-Za-z-]+',
'pass' => ['slug']
]
);

zf2 translate validators messages with variables

I have custom message like this:
'options' => array(
'min' => $min,
'max' => $date->format('Y-m-d'),
'inclusive' => true,
'messages' => array(
Between::NOT_BETWEEN => "The input is not between '%min%' and '%max%', inclusively",
),
),
I put this string in .po file and generate .mo, but message won't translate. For all other messages without variables it's working fine.
You can read in the ZF2 official documentation on how to do this.
The translation files for validators are located at /resources/languages. You should simply attach a translator to Zend\Validator\AbstractValidator using these resource files or in your case your own file for your custom messages.
$validator->setDefaultTranslator($translator);
EDIT
I misinterpreted your question, here an edit
Can you not translate the message before binding the variables like this:
$translator = ...translator...
'options' => array(
'min' => $min,
'max' => $date->format('Y-m-d'),
'inclusive' => true,
'messages' => array(
Between::NOT_BETWEEN => $translator->translate(
"The input is not between '%min%' and '%max%', inclusively"
),
),
),
It would have been nice, if you had given more explanation.
Generally If string contains variables , You have to replace them with string formatters.
In your case msgid "The input is not between %s and %s"
I hope it should solve your problem.

How to handle GET params within urlManager's rule in Yii?

I pass a query string to SearchController::actionDefault in form of GET parameter q:
/search/?q=...
However I need to define a rule that would automatically initialize this parameter with some value or define another param.
If I'll request mysite.com/showall I need get the same content like in /search/?q=*
This is what I've tried:
'/showall' => '/search/default/index/?r=*',
I solved this!
there is possible to set defaultParams in urlManager, and finaly it looks like in application config file:
...
'components' => array(
...
'urlManager' => array(
...
'rules' => array(
....
'/show_all' => array( '/search/default/index', 'defaultParams' => array('show_all'=>'-') ),
....
),
...
),
...
),
The accepted answer also works when you are getting different requests and you need to map it to the same GET param.
For example I want all of these requests:
user/pics
user/photos
user/pictures
to actually generate: user/index?content=photos.
This might be one of a way to go:
'<controller:user>/(<content:photos>|pics|pictures)' => array('<controller>/index', 'defaultParams'=>array('content'=>'photos')),

Use drupal_goto with named anchor in url

i am trying to go to an location choosen by my script.
I'm using url() and drupal_goto() to archive this, but the fragment-option named at the url()-documentation-page seems not working like i understand it or more likely drupal_goto() is changing the link.
The link-string i want should look like:
/topsection/section#subsection
but instead i'm getting the hash-sign encoded like
/topsection/section%23subsection
Here is my code:
$section = url( '/topsection/' . 'section', array( 'fragment' => 'subsection', 'alias' => TRUE ) );
drupal_goto( $section );
Any help would be nice!
Thank you.
Ha! just found the solution:
I misunderstood the documentation.
It is correctly telling that i should use drupal_goto() with fragment/anchor passed as option like i would give to url().
This is working:
drupal_goto( '/topsection/' . 'section',
array(
'fragment' => 'subsection',
'alias' => TRUE ) );

Resources