basz / SlmLocale

Auto detection of locale through different strategies for Zend Framework 2
Other
68 stars 34 forks source link

how can i render combobox : $this->LocaleMenu() #58

Closed excennfahnfah1976 closed 10 years ago

excennfahnfah1976 commented 10 years ago

How can i render locales in a combobox. i use "$this->LocaleMenu()" this view helper but i want to show a combobox not ul list.

juriansluiman commented 10 years ago

I would create a new view helper, extend the localeMenu helper and use that one instead. The only thing you need to extend is this part.

In your config:

'view_helpers' => array(
  'factories' => array(
    'localecombobox' => 'MyModule\Service\LocaleComboboxViewHelperFactory',
  ),
),

Then you factory:

namespace MyModule\Service;

use MyModule\View\Helper\LocaleCombobox;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class LocaleComboboxViewHelperFactory implements FactoryInterface
{
    /**
     * @param  ServiceLocatorInterface $serviceLocator
     * @return LocaleMenu
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $detector = $serviceLocator->getServiceLocator()->get('SlmLocale\Locale\Detector');

        $helper = new LocaleCombobox;
        $helper->setDetector($detector);

        return $helper;
    }
}

Then your helper:


namespace MyModule\View\Helper;

use SlmLocale\View\Helper\LocaleMenu;

class LocaleCombobox extends LocaleMenu
{
    public function __toString()
    {
        // here your code
    }
}
excennfahnfah1976 commented 10 years ago

ok thank you very much

excennfahnfah1976 commented 10 years ago

Sorry one question. I get this error : Fatal error: Class 'Application\View\Helper\Locale' not found in /var/www/zf2-tutorial/module/Application/src/Application/View/Helper/LocaleCombobox.php on line 15

juriansluiman commented 10 years ago

Ah you need to import Locale as well. Put use Locale; just below the namespace declaration.

excennfahnfah1976 commented 10 years ago

Thank you, it work very good ;)