1. Go to this page and download the library: Download josegonzalez/cakephp-sham library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
josegonzalez / cakephp-sham example snippets
class AppController extends Controller {
public $components = array('Sham.Sham');
public $helpers = array('Sham.Sham');
}
class UsersController extends AppController {
public function profile($username = null) {
// Some code that works with user profiles
}
public function _seoProfile() {
// Called in the beforeRender() if the action was successfully processed
$user = $this->viewVars['user'];
$this->Sham->loadBySlug('view/' . $user['User']['username']);
// Set some defaults in case the record could not be loaded from the DB
$description = "awesome description of the page, with some good default keywords, referencing {$user['User']['username']}";
$keywords = array($user['User']['username'] . ' profile', 'profiles', 'social network');
$this->Sham->setMeta('title', "{$user['User']['username']}'s Profile | Social Network");
$this->Sham->setMeta('description', $description);
$this->Sham->setMeta('keywords', implode(', ', $keywords));
$this->Sham->setMeta('canonical', "/view/{$user['User']['username']}/", array('escape' => false));
}
}
class AppController extends Controller {
public $components = array('Sham.Sham');
public $helpers = array('Sham.Sham');
public function _seoFallback() {
// ... code ...
}
}