2017 © Pedro Peláez
 

cakephp-plugin seo

A CakePHP plugin for managing SEO

image

davidyell/seo

A CakePHP plugin for managing SEO

  • Friday, April 20, 2018
  • by davidyell
  • Repository
  • 4 Watchers
  • 9 Stars
  • 382 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 16 Versions
  • 8 % Grown

The README.md

CakePHP-Seo

Build Status Coverage Status, (*1)

What is it?

I always need to add meta tags to my pages for SEO purposes and it was getting tedious writing tools to complete this every time. So I created a component which hooks the event system to catch the beforeLayout event to inject SEO data into the view variables., (*2)

I found that by containing all the functionality for SEO inside a component it makes it easier to manage., (*3)

Requirements

  • CakePHP 3.6+
  • PHP 7.2+

Installation

https://packagist.org/packages/davidyell/seo, (*4)

composer require davidyell/seo

Setup

Firstly you will need to load the plugin in your /config/bootstrap.php., (*5)

Plugin::load('Seo');

Then you will need to attach it to the controller you want it to run on. I tend to attach it to my AppController., (*6)

// src/Controller/AppController.php initialize() method
$this->loadComponent('Seo.Seo' => [
    'defaults' => [
        'title' => 'Dave is epic',
        'description' => 'This is an epic plugin for epic people',
        'keywords' => 'epic,plugin'
    ]
];

There are a number of configuration settings you will need to change to match your setup. You can find these in the $settings class variable in the component. Primarily you will want to change the $settings['defaults'] to set the default title, description and keywords for your website., (*7)

How it works

The idea is that your model will have some fields editable in the CMS for SEO. Once this data is set to the view, the component will catch the data and inject it into your layout for you automatically., (*8)

As such your layout will need some things to exist in order for the component to correctly add the data., (*9)

// For the page title
echo $this->fetch('title');

// For outputting the meta tags inside <head>
echo $this->fetch('meta');

Database configuration

This is for you to do. How you store your SEO data is outside the scope of this plugin. However I would recommend creating fields either in your Contents table or associated to it, with seo_title VARCHAR(255), seo_description TEXT, and seo_keywords VARCHAR(255)., (*10)

Tips and Tricks

Got two viewVars set in your controller and you want to change it up depending on which is set?, (*11)

// ProvidersController::beforeRender()

if (isset($this->viewVars['content'])) {
    $this->components()->get('Seo')->setConfig('viewVar', 'article');
} elseif (isset($this->viewVars['provider'])) {
    $this->components()->get('Seo')->setConfig('viewVar', 'provider');
}

The viewVar access accepts a hash path, so you can use dot notation to access deeply nested data., (*12)

$this->Components->load('Seo.Seo', [
    'viewVar' => 'catalog',
    'fields' => [
        'title' => 'assigned_content.content.seo_title'
    ]
]);

Don't forget that you can set the config directly on an instance of the component., (*13)

// ExamplesController.php

$this->components()->get('Seo')->setConfig('fields.title', 'My new title');

Error handler middleware

It is very helpful to be able to catch 404 errors and use them to manage your SEO redirecting. This allows for only urls which do not match your application to be redirecting, avoiding any overhead., (*14)

The plugin provides a basic middleware for this purpose which can be implemented into your /src/Application.php, (*15)

$this->redirects = [
    '/examples/first-example' => [
        'target' => '/tutorials/first',
        'code' => 301
    ]
];
$queue->add(new \Seo\Error\Middleware\ErrorHandlerMiddleware($this->redirects))

The Versions

20/04 2018

dev-master

9999999-dev

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

The Development Requires

20/04 2018

3.1.2

3.1.2.0

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

The Development Requires

01/02 2018

3.1.1

3.1.1.0

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

The Development Requires

11/12 2017

3.1.0

3.1.0.0

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

The Development Requires

07/04 2017

3.0.1

3.0.1.0

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

The Development Requires

27/07 2015

3.0.0

3.0.0.0

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

The Development Requires

11/03 2015

2.x-dev

2.9999999.9999999.9999999-dev

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

11/03 2015

1.0.0

1.0.0.0

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

14/10 2014

0.1.2

0.1.2.0

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

31/07 2014

0.1.1

0.1.1.0

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

25/07 2014

0.1.0

0.1.0.0

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

24/07 2014

0.0.6

0.0.6.0

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

17/07 2014

0.0.5

0.0.5.0

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

17/06 2014

0.0.4

0.0.4.0

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

30/05 2014

0.0.3

0.0.3.0

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires

 

30/05 2014

0.0.2

0.0.2.0

A CakePHP plugin for managing SEO

  Sources   Download

MIT

The Requires