PHP code example of contenir / contenir-audience-mezzio
1. Go to this page and download the library: Download contenir/contenir-audience-mezzio 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/ */
contenir / contenir-audience-mezzio example snippets
new PhpFileProvider(realpath(__DIR__) . '/autoload/{{,*.}global,{,*.}local}.php'),
new PhpFileProvider(realpath(__DIR__) . '/autoload/extensions/{{,*.}global,{,*.}local}.php'),
// config/autoload/audience.global.php
return [
'contenir_audience' => [
'handle' => 'campaign-monitor', // the add-on: its tables are ext_campaign_monitor_*
'adapter' => PhpDb\Adapter\Adapter::class, // the site's database; default AdapterInterface::class
'clock' => null, // a PSR-20 clock service; default the system's time
],
];
use Contenir\Audience\Exception\StorageException;
use Contenir\Audience\Mezzio\Subscriptions;
final class SubscribeHandler implements RequestHandlerInterface
{
public function __construct(private Subscriptions $subscriptions, /* … */) {}
public function handle(ServerRequestInterface $request): ResponseInterface
{
// … validate the form …
try {
$this->subscriptions->subscribe(
'newsletter',
$data['email'],
['name' => $data['name'] ?? ''],
ip: $request->getServerParams()['REMOTE_ADDR'] ?? null,
);
} catch (StorageException) {
// the outbox row couldn't be written: the one failure to show the visitor
}
// … render "thanks" …
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.