PHP code example of clesson-de / silverstripe-contacts

1. Go to this page and download the library: Download clesson-de/silverstripe-contacts 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/ */

    

clesson-de / silverstripe-contacts example snippets


$owner = Contact::current_site_owner();

use Clesson\Silverstripe\Contacts\Models\Contact;

// Get a single contact by its URL slug
$contact = Contact::get_by_slug('roy-orbison');

// Get all contacts with a specific tag (by unique key)
$clients = Contact::get_by_tag('client');

// Get the site owner
$owner = Contact::current_site_owner();

use Clesson\Silverstripe\Contacts\Models\Company;
use Clesson\Silverstripe\Contacts\Models\Person;
use Clesson\Silverstripe\Contacts\Models\Employee;

// Create a company
$company = Company::create();
$company->Name1 = 'Acme Inc.';
$company->write();

// Create a person
$person = Person::create();
$person->FirstName = 'Jane';
$person->LastName  = 'Doe';
$person->write();

// Create an employee linking person and company
$employee = Employee::create();
$employee->PersonID  = $person->ID;
$employee->CompanyID = $company->ID;
$employee->write();

// Each contact type returns a formatted full name
echo $company->getFullName();  // "Acme Inc."
echo $person->getFullName();   // "Jane Doe"
echo $employee->getFullName(); // "Jane Doe (Acme Inc.)"