Deprecated: Creation of dynamic property Timber\Site::$pingback is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Site.php on line 180

Deprecated: Creation of dynamic property Timber\User::$name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/User.php on line 118

Deprecated: Creation of dynamic property Timber\Post::$has_disclaimer is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_lock is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_last is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_meta_box_present is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_send_notification is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_modify_title_and_content is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_notification_custom_heading is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_notification_custom_content is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$tipologia is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_tipologia is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$attributi is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_attributi is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$in_evidenza_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_in_evidenza_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$inviato_in_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_inviato_in_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$fonte is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_fonte is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$fonte_url is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_fonte_url is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_category is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_blz_affiliation_attributes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_content_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_attributes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_speciali is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_focuskw is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_linkdex is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_content_score is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_focuskeywords is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_keywordsynonyms is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_estimated-reading-time-minutes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_wordproof_timestamp is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_thumbnail_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_metadesc is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$response_body is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_indexnow_last_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_date_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ping_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_password is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$to_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$pinged is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_content_filtered is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$guid is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$menu_order is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_mime_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_count is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$filter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71
Il database WordPress non ha più segreti grazie a Corcel

Il database WordPress non ha più segreti grazie a Corcel

Cos'è e come funziona Corcel, innovativo software per accedere al database di WordPress da qualsiasi applicazione PHP.

Con l’espressione Object-Relational Mapping (ORM) si fa comunemente riferimento a un concetto fondamentale nello sviluppo software, in particolare quando si lavora con database relazionali. ORM è una tecnica di programmazione che permette di interagire con un RDBMS (Relational database management system) utilizzando oggetti del linguaggio utilizzato. Questo approccio solleva lo sviluppatore dalla “scocciatura” di scrivere direttamente onerose query SQL. Un CMS come WordPress è ormai utilizzato in molteplici contesti, per gestire una vasta schiera di campi applicativi. Il database di WordPress è quindi un vero e proprio “tesoro” di informazioni che spesso professionisti e aziende desiderano collegare con altri software.

Estrarre dati dal database WordPress e accedervi da altre applicazioni

Vi siete mai chiesti come estrapolare informazioni importanti dal database di WordPress per elaborarle con altre applicazioni aziendali? Se la risposta è sì, sappiate che non siete i soli.

Corcel è un progetto open source, recentemente pubblicato su GitHub, che permette di utilizzare WordPress come backend o CMS per l’inserimento di contenuti, e qualsiasi altra applicazione PHP per interrogare quei dati.

L’idea alla base di Corcel è di creare un ponte tra il mondo WordPress e quello delle moderne applicazioni PHP, in particolare quelle basate su framework come Laravel.

Il software Corcel sfrutta Eloquent, l’ORM di Laravel, per mappare le tabelle del database WordPress in modelli PHP orientati agli oggetti. Questo permette agli sviluppatori di interagire con i dati WordPress utilizzando un’API familiare, potente e versatile.

L’astrazione di alto livello fornita da Corcel, nasconde la notevole complessità della struttura dei database WordPress. È così possibile mettere a disposizione degli sviluppatori un’interfaccia pulita e intuitiva per l’accesso ai dati gestiti da WordPress.

Pur essendo ottimizzato per l’uso con Laravel, Corcel può essere utilizzato in qualsiasi progetto PHP che supporti Composer. Questa particolarità rende Corcel uno strumento versatile per diversi contesti di sviluppo.

Esempi di utilizzo di Corcel

Corcel si impegna a mantenere la compatibilità con le strutture dati di WordPress, permettendo agli sviluppatori di lavorare con un database WordPress esistente senza dover applicare alcun genere di modifica. Sfruttando le ottimizzazioni di Eloquent, Corcel mira addirittura a offrire prestazioni migliori rispetto all’accesso diretto al database WordPress con le funzioni native.

Il software consente ad esempio di creare API RESTful per un sito WordPress. Nell’esempio seguente, un endpoint che permette di visualizzare i post di WordPress facendo leva unicamente su di un controller Laravel:

use Corcel\Model\Post;

class PostController extends Controller
{
    public function index()
    {
        $posts = Post::published()
                     ->orderBy('post_date', 'desc')
                     ->paginate(10);
        
        return response()->json($posts);
    }

    public function show($slug)
    {
        $post = Post::slug($slug)
                    ->with(['meta', 'categories', 'tags'])
                    ->firstOrFail();
        
        return response()->json($post);
    }
}

Vedete quanto è semplice interagire con un database WordPress grazie a Corcel, senza dover “impazzire” nell’apprendimento della struttura del database e nella creazione di query SQL “ad hoc”?

Con Corcel si possono integrare i dati provenienti da WordPress in un’applicazione Laravel/PHP, abilitare una ricerca avanzata di contenuti sulla base dati WordPress, gestire il menu di WordPress in un’applicazione personalizzata, rielaborare direttamente tutti i dati conservati da WooCommerce e molto altro ancora.

Come WordPress, Corcel è progettato per essere estensibile. Gli sviluppatori possono creare modelli personalizzati, aggiungere metodi e scope, e adattare il comportamento di Corcel alle specifiche esigenze di progetto.

Come usare Corcel

Per iniziare, Corcel va installato tramite Composer:

composer require jgrossi/corcel

Gli utenti di Laravel possono quindi usare la sintassi seguente per poi specificare i dettagli della connessione al database WordPress nel file config\corcel.php:

php artisan vendor:publish --provider="Corcel\Laravel\CorcelServiceProvider"

Chi non utilizza Laravel, deve configurare la connessione al database manualmente:

use Corcel\Database;

Database::connect([
'database' => 'database_name',
'username' => 'username',
'password' => 'password',
'prefix' => 'wp_'
]);

A questo punto, si può fare riferimento agli esempi pubblicati nella home page del progetto per iniziare a interagire con il database di WordPress da qualsiasi applicazione.

Ti consigliamo anche

Link copiato negli appunti