Frage

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&param_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&param_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('&amp;', $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.

War es hilfreich?

Lösung

Andere Tipps

PHP has a native function for doing this, see: http://www.php.net/manual/en/function.http-build-query.php

If you use MVC, ZF does not use query strings the traditional way.

You could create your own helper, though:

http://blog.lysender.com/2009/04/creating-your-own-helper-zend-framework/

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top