Can anyone tell me if it is possible to mix views arguments with static strings?
For example in the path section of a view fee开发者_如何转开发d display I need:
/mypath/%.xml
with the ".xml" part being the static string.
Thanks in advance.
I figured it out finally.
Under validation, choose PHP code. Then I entered:
// strip ".xml" from incoming
$new_arg = preg_replace('/\.xml$/', '', $argument ); argument
$handler->argument = $new_arg;
return TRUE; //must return something
That works. Now Drupal sends "foo" to the SQL query, even if the incoming argument via the url is "foo.xml"
I just tested this, and you can't do the exact path you posted above. Views appears to only recognize '%' as an argument placeholder if it sits between slashes, or by itself at the end. So, what will work is something like this:
/mypath/%/rss.xml
or
/mypath/static/%
In path, anyway, you should set path/%
But you can check argument %.xml in validating code:
In views argument additing/editing window:
Validator options - Validator - PHP Code:
Enter PHP code that returns TRUE or FALSE. No return is the same as FALSE, so be SURE to return something if you do not want to declare the argument invalid. Do not use . The argument to validate will be "$argument" and the view will be "$view". You may change the argument by setting "$handler->argument".
Use strpos to check if there xml string.
Also you can modify argument as it wrote in comment: $handler->argument
精彩评论