PHP code example of ciebit / news

1. Go to this page and download the library: Download ciebit/news 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/ */

    

ciebit / news example snippets




iebit\News\News;
use Ciebit\News\Status;
use Ciebit\News\Factory\NewsFactory;
use Ciebit\News\Storages\Database\Sql;
use PDO;

$news = (news NewsFactory)
    ->setTitle('Title News')
    ->setStatus(Status::ACTIVE())
    ->setBody('Text')
    ->create();

$database = new Sql(new PDO('mysql:dbname=cb_news;host=localhost;charset=utf8', 'user', 'password'));
$id = $database->store($news);

echo $id;



iebit\News\Storages\Database\Sql;
use PDO;

$database = new Sql(new PDO('mysql:dbname=cb_news;host=localhost;charset=utf8', 'user', 'password'));
$newsCollection = $database->addFilterById('=', '1')->find();

echo $newsCollection->getArrayObject()->offsetGet(0)->getTitle();




iebit\News\Storages\Database\Sql;
use DateTime;
use PDO;

$database = new Sql(new PDO('mysql:dbname=cb_news;host=localhost;charset=utf8', 'user', 'password'));
$newsCollection = $database->addFilterByDateTime('>', new DateTime('2019-07-06'))->find();

foreach($newsCollection as $news) {
    echo $news->getTitle() . PHP_EOL;
}