I am just curious & confused, because I considered Zend Framework as having tools for pretty much almost everything you may need when building a web application.
In Zend Framework parameters are usually passed within URL as /param_name/param_value
, but if I want to build an URL ending with "?param_name=param_value¶m_name2=param_value2
" it seems I have to build this query string myself and pass it as string like that:
<a href="<?php echo $this->url(array('controller'=>'index','action'=>'form'),NULL,TRUE)."?param_name=param_value¶m_name2=param_value2";?>" title="">
Some link
</a>
Does Zend Framework - which was quite complex in my opinion - have a helper for building such query strings? I searched for that and did not find anything.
What I am looking for is something that works similarly to this, but more reliable:
function query_string(array $params) {
$keys = array_keys($params);
$vals = array_values($params);
$build_param_func = create_function('$a,$b','return $a."=".$b;');
$query_string_parts = array_map($build_param_func, $keys, $vals);
return '?'.implode('&', $query_string_parts);
};
See its demo here: http://ideone.com/piCNj
If Zend Framework does not have such simple helper, is there any module that provides it? Or is it completely up to developer to create such function / helper?
Thanks for your answers.
Use http_build_query