By default, WordPress adds <link rel="shortlink"> meta tag to the <head> of a website and uses the short url like https://mixable.blog/?p=12345 for this. When you already use nice slugs as permalink structure, such a tag is not necessary, because you already have unique urls.
To remove the shortlink tag, you can use an additional plugin or simply add some code to your themes functions.php:
This error happened after moving a WordPress installation to another server. The new server had a different linux distribution and a newer PHP version. In my case, the environment changed from PHP 7.4 to PHP 8.2.
I already added some missing PHP extensions and updated the configuration to match the old one, but the error still exists.
At the end, this could be solved by adding the following code in wp-config.php file:
Life is already very complex, so let’s simplify your projects by removing all the jQuery code. Plain JavaScript provides the same functionalities and it does not require any additional frameworks. And it’s supported by most of the modern browsers out of the box. This is a list of replacements for your daily used jQuery methods.
$() or jQuery()
Return a collection of matched elements either found in the DOM based on passed argument(s) or created by passing an HTML string.
// jQuery implementationvarelement = $(selector);// Plain JavaScriptvarelement = document.querySelector(selector); // Single elementvarelements = document.querySelectorAll(selector); // Multiple elements
.addClass()
Adds the specified class(es) to each element in the set of matched elements.
Add or remove one or more classes from each element in the set of matched elements, depending on either the class’s presence or the value of the state argument.
CakePHP bietet mit Migrations die Möglichkeit, Änderungen an der Datenbankstruktur einzuspielen oder rückgängig zu machen. Der typische Ablauf zur Migration ist folgender:
Generating migrations from an existing database
If you are dealing with a pre-existing database and want to start using migrations, or to version control the initial schema of your application’s database, you can run the migration_snapshot command:
bin/cake bake migration_snapshot Initial
Generating a diff between two database states
You can generate a migrations file that will group all the differences between two database states using the migration_diff bake template. To do so, you can use the following command:
bin/cake bake migration_diff NameOfTheMigrations
Applying Migrations
Once you have generated or written your migration file, you need to execute the following command to apply the changes to your database:
bin/cake migrations migrate
Migrations Status
The Status command prints a list of all migrations, along with their current status. You can use this command to determine which migrations have been run:
In den Einstellungen der AuthComponent lässt sich festlegen, welches Feld der Datenbank für das Login verwendet werden soll. Hier kann allerdings nur ein einzelner Wert angegeben werden (bspw. username oder email). Um jedoch bei der Eingabe des Logins sowohl Benutzername, als auch Email zu erlauben, kann man die Einstellung zur Laufzeit (also beim Aufruf des Controllers) anpassen und das entsprechende Feld setzen. Und zwar wie folgt:
src/Controller/AppController.php
use Cake\Controller\Controller;
class AppController extends Controller
{
public function initialize()
{
parent::initialize();
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => ['username' => 'username', 'password' => 'password'],
]
],
]);
}
}
src/Controller/UsersController.php
use App\Controller\AppController;
use Cake\Validation\Validation;
class UsersController extends AppController
{
public function login()
{
if ($this->request->is('post')) {
if (Validation::email($this->request->getData('username'))) {
$this->Auth->config('authenticate', [
'Form' => [
'fields' => ['username' => 'email']
]
]);
$this->Auth->constructAuthenticate();
$this->request->data['email'] = $this->request->getData('username');
}
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Invalid combination of username/email and password.'));
}
}
}
Unter http://grafikart.github.io/CakePHP-Media/index_en.html gibt es ein klasse CakePHP Plugin, mit dem sich Dateien verschiedenster Art (vorzüglich Grafiken, aber auch: png, jpg, pdf, mov, …) mit den Datensätzen anderer Models verknüpfen lassen. Im Video-Tutorial der Webseite wird ausführlichst beschrieben, wie dieses Plugin verwendet wird. Sehr zu empfehlen!
Eine einfache Möglichkeit, um das Versenden von Emails in CakePHP 2.x zu testen, ist die Debug-Einstellung der Email Konfiguration. Dabei genügt das Setzen der Transport-Einstellung auf ‘Debug’ und schon wird der Inhalt der Email an der entsprechenden Stelle angezeigt:
<?php
// app/Config/email.php
class EmailConfig {
public $default = array(
'transport' => 'Debug',
// ...
Dies funktioniert allerdings nur, wenn man sich die Ausgabe des aufgerufenen Scripts anzeigen lassen kann. Bei Cronjobs beispielsweise wird dies schon schwieriger.
Shells lassen sich in CakePHP auch für den Aufruf aus Cronjobs verwenden. Dabei kann es jedoch vorkommen, dass der Aufruf einer Shell über das Terminal ohne Probleme funktioniert, aber im späteren Einsatz beim Aufruf über einen Cronjob nicht mehr so richtig will. Es hatte mich einiges an Zeit gekostet, herauszufinden warum dies passieren kann: