src/View/Helper/CommonHelper.php
public function metaAlternate($url, $lang, $full = false) {
		//$canonical = $this->Url->build($url, $full);
		$url = $this->Url->build($url, $full);
		//return $this->Html->meta('canonical', $canonical, array('rel'=>'canonical', 'type'=>null, 'title'=>null));
		$lang = (array)$lang;
		$res = [];
		foreach ($lang as $language => $countries) {
			if (is_numeric($language)) {
				$language = '';
			} else {
				$language .= '-';
			}
			$countries = (array)$countries;
			foreach ($countries as $country) {
				$l = $language . $country;
				$options = ['rel' => 'alternate', 'hreflang' => $l, 'link' => $url];
				$res[] = $this->Html->meta($options) . PHP_EOL;
			}
		}
		return implode('', $res);
	}
public function metaAlternate($url, $lang, $full = false) {
		//$canonical = $this->Url->build($url, $full);
		$url = $this->Url->build($url, $full);
		//return $this->Html->meta('canonical', $canonical, array('rel'=>'canonical', 'type'=>null, 'title'=>null));
		$lang = (array)$lang;
		$res = [];
		foreach ($lang as $language => $countries) {
			if (is_numeric($language)) {
				$language = '';
			} else {
				$language .= '-';
			}
			$countries = (array)$countries;
			foreach ($countries as $country) {
				$l = $language . $country;
				$options = ['rel' => 'alternate', 'hreflang' => $l, 'link' => $url];
				$res[] = $this->Html->meta($options) . PHP_EOL;
			}
		}
		return implode('', $res);
	}
public function metaAlternate ( $ url , $ lang , $ full = false ) { //$canonical = $this->Url->build($url, $full); $ url = $ this -> Url -> build ( $ url , $ full ) ; //return $this->Html->meta('canonical', $canonical, array('rel'=>'canonical', 'type'=>null, 'title'=>null)); $ lang = ( array ) $ lang ; $ res = [ ] ; foreach ( $ lang as $ language => $ countries ) { if ( is_numeric ( $ language ) ) { $ language = '' ; } else { $ language .= '-' ; } $ countries = ( array ) $ countries ; foreach ( $ countries as $ country ) { $ l = $ language . $ country ; $ options = [ 'rel' => 'alternate' , 'hreflang' => $ l , 'link' => $ url ] ; $ res [ ] = $ this -> Html -> meta ( $ options ) . PHP_EOL ; } } return implode ( '' , $ res ) ; }
Convenience method for "alternate" SEO links

@param string|array $url
@param string|array $lang (lang(iso2) or array of langs)
lang: language (in ISO 6391-1 format) + optionally the region (in ISO 3166-1 Alpha 2 format)
- de
- de-ch
etc
@param bool $full
@return string HTML Markup
Convenience method for alternate SEO links