php – Cakephp – function unable to return h1-ThrowExceptions

Exception or error:

I have this next problem with SEO-related problems.
I am trying to form an h1 title for a specific page that I have in my web project.
What I am trying to achieve is to be able to display a certain key phrase for that page but the thing is that in the bit where I am trying to return the data, which in this case I am including h1, the meta title, and the meta description, it doesn’t return what I want to.
It does return a certain bit of the initial key phrase, but the rest of the bit won’t appear.

  private function getMetaTitleH1MetaDescByParams($h1MetaTitleData, $lang) {
    $spec_id = $h1MetaTitleData['specialty_id'];
    $treatment_id = $h1MetaTitleData['treatment_id'];
    $doctorsCount = $h1MetaTitleData['doctors_count'];
    $specialty_name = $h1MetaTitleData['specialty_name'];
    $title = "$doctorsCount $specialty_name siempre cerca de ti con Telemedicina | Top Doctors";
    $h1 = __('Telemedicina') . __('con') . $specialty_name;
    $metaDesc = "";

    $specialtyAndTreatment = isset($spec_id) && isset($treatment_id);
    $onlyTreatment = !isset($spec_id) && isset($treatment_id);
    $onlySpecialty = isset($spec_id) && !isset($treatment_id);

    switch (true) {
        case $specialtyAndTreatment:
            return $this->generateTitleH1MetaDescSpecialtyTreatment($h1MetaTitleData);
        case $onlyTreatment:
            return $this->generateTitleH1MetaDescTreatment($h1MetaTitleData, $lang);   
        case $onlySpecialty:
            pr($onlySpecialty." onlySpecialty");
            return $this->generateTitleH1MetaDescSpecialty($h1MetaTitleData, $lang);
        default:
            return array('title' => $title, 'h1' => $h1, 'metaDesc' => $metaDesc);
    }
}
   private function generateTitleH1MetaDescSpecialty($h1MetaTitleData, $lang) {
    $province_id = $h1MetaTitleData['province_id'];
    $city_id = $h1MetaTitleData['city_id'];
    $doctorsCount = $h1MetaTitleData['doctors_count'];
    $specialty_name = $h1MetaTitleData['specialty_name'];
    $specialist_name_singular = $h1MetaTitleData['specialist_name_singular'];
    $province_name = $h1MetaTitleData['province_name'];
    $city_name = $h1MetaTitleData['city_name'];

    if (isset($city_id)) {
        return $this->getSpecialtyCityMetaData($doctorsCount, $specialty_name, $city_name, $lang);
    } else if (isset($province_id)) {
        return $this->getSpecialtyProvinceMetaData($specialty_name, $specialist_name_singular, $province_name);
    } else {
        pr("Enters here");
        return $this->getSpecialtyMetaData($specialty_name, $specialist_name_singular, $specialist_name_singular);
    }

}


function getSpecialtyMetaData($specialty_name, $specialist_name_singular, $specialist_name) {
    pr($specialty_name);
    return array(
        'title' => __('Telemedicina con especialistas en') . sprintf(' %s | Top Doctors', $specialty_name),
        'h1' => __('Telemedicina') . ' ' . __('con'). sprintf( ' %s', $specialist_name),
        'metaDesc' => sprintf("¿Necesitas un %s y no tienes un centro médico cerca? Contacta con el mejor especialista "
                    . "para tu caso en cualquier momento y lugar a través de la telemedicina. Chatea o realiza "
                    . "una videoconferencia con un experto para resolver tus dudas o tener una segunda opinión médica.", $specialist_name_singular)
    );
 }

When I am returning the array for my h1 I get the next part, but no the total part that I already assigned on my second function.
Result now is: Telemedicina con

The expected result would be: Telemedicina con $specialist_name
The $specialist_name whenever I am doing print_r it does get printed at the very beginning of the top of my website, but when I am trying to include it to my view, it won’t appear at all.

I am attaching also the bit where I am calling the function to my main function which serves for displaying my view.

  $h1MetaTitleData = array(
            'specialty_id' => $searchData['specialty_id'],
            'treatment_id' =>  $searchData['treatment_id'],
            'province_id' => $searchData['province_id'],
            'city_id' =>  $searchData['city_id'],
            'specialist_name' => $especialista,
            'specialist_name_singular' => $specialistSingular,
            'specialty_name' => $searchData['specialty_name'],
            'treatment_name' => $searchData['treatment_name'],
            'province_name' =>  ucfirst($searchData['province_name']),
            'city_name'=> ucfirst($searchData['city_name']),
            'doctors_count' => count($resultado),
  );
        $titleH1MetaDesc = $this->getMetaTitleH1MetaDescByParams($h1MetaTitleData, $lang);

        pr($titleH1MetaDesc);
        $this->metaTitle = $titleH1MetaDesc['title'];

        $h1 = $titleH1MetaDesc['h1'];
        $this->metaDescription = $titleH1MetaDesc['metaDesc'];

        $this->set('title_for_layout', $this->metaTitle);

        $this->set(compact('valueShortDesc', 'valueShortDescAfter', 'espectreat', 'urls', 'resultado', 'valueText', 'treatmentId', 'h1', 'ErrorText', 'citySearchHasData'));

If anyone can give me a hint on how to tackle the problem I am having, it would be quite appreciating,

Thanks!

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *