Jump to content

[SOLVED] How to make first letter Uppercase?


servetsarap

Recommended Posts

Hello,

 

I've a override file to make search page's title as query. But I want to make first letter uppercase. When I add ucfirst, the page gives http500 error. Where do I need to add ucfirst()?

 

Here is the code:

 

<?php

class Meta extends MetaCore
{
    public static function getMetaByPage($page, $id_lang)
    {
        $search_translations = array(1 => "Search results for query", 2 => "Recherche résultats pour requête");
        $tag_translations = array(1 => "Search results for tag", 2 => "Recherche résultats pour tag");
        
        
if ($page == 'search' && Tools::getValue('search_query'))
            return array('title' => Tools::getValue('search_query'), 'description' => (isset($search_translations[$id_lang]) ? $search_translations[$id_lang] : $search_translations[1])." '".Tools::getValue('search_query')."'");
        elseif ($page == 'search' && Tools::getValue('tag'))
            return array('title' => Tools::getValue('tag'), 'description' => (isset($tag_translations[$id_lang]) ? $tag_translations[$id_lang] : $tag_translations[1])." '".Tools::getValue('tag')."'");
        else
            return parent::getMetaByPage($page, $id_lang);
    }
}

 

Edited by servetsarap (see edit history)
Link to comment
Share on other sites

When you are working with PrestaShop, you should use PrestaShop specific function. So use Tools::ucfirst() and i can't find ucfirst() function in your code.

 

Try following code:

class Meta extends MetaCore
{
	public static function getMetaByPage($page, $id_lang)
	{
		$search_translations = array(1 => "Search results for query", 2 => "Recherche résultats pour requête");
		$tag_translations = array(1 => "Search results for tag", 2 => "Recherche résultats pour tag");

		if ($page == 'search' && Tools::getValue('search_query'))
			return array('title' => Tools::ucfirst(Tools::getValue('search_query')), 'description' => (isset($search_translations[$id_lang]) ? $search_translations[$id_lang] : $search_translations[1]).
					" '".Tools::getValue('search_query')."'");
		elseif ($page == 'search' && Tools::getValue('tag'))
			return array('title' => Tools::ucfirst(Tools::getValue('tag')), 'description' => (isset($tag_translations[$id_lang]) ? $tag_translations[$id_lang] : $tag_translations[1]).
					" '".Tools::getValue('tag')."'");
		else
			return parent::getMetaByPage($page, $id_lang);
	}
}
Edited by modprestashop (see edit history)
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...