PHP code example of se7enxweb / primer

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

    

se7enxweb / primer example snippets


// apps/site/config/routing.php
$routing->connect('articles', new sfRoute('/articles', [
    'module' => 'article',
    'action' => 'index',
]));
$routing->connect('article_show', new sfRoute('/articles/:slug', [
    'module' => 'article',
    'action' => 'show',
], ['slug' => '[a-z0-9\-]+']));

// apps/site/modules/article/actions/actions.class.php
class articleActions extends sfMicroAction
{
    public function executeIndex(): string
    {
        $pdo = new PDO('mysql:host=127.0.0.1;dbname=myapp;charset=utf8mb4', 'user', 'pass');
        $this->articles = $pdo->query('SELECT * FROM articles ORDER BY created_at DESC LIMIT 10')
                              ->fetchAll(PDO::FETCH_ASSOC);
        $this->title = 'Latest Articles';
        return sfView::SUCCESS;
    }

    public function executeShow(): string
    {
        $pdo = new PDO('mysql:host=127.0.0.1;dbname=myapp;charset=utf8mb4', 'user', 'pass');
        $stmt = $pdo->prepare('SELECT * FROM articles WHERE slug = ? LIMIT 1');
        $stmt->execute([$this->getRequest()->getParameter('slug')]);
        $this->article = $stmt->fetch(PDO::FETCH_ASSOC);
        if (!$this->article) {
            $this->forward404();
        }
        $this->title = $this->article['title'];
        return sfView::SUCCESS;
    }
}

<!-- apps/site/modules/article/templates/indexSuccess.php -->
<h1> echo htmlspecialchars($title) 

HTTP Request
      │
      ▼
   Web Server (Apache / Nginx)  →  DocumentRoot: public/
      │
      ▼
  public/index.php  ──  sfCoreAutoload + (optional) Composer vendor/autoload.php
      │
      ├── sfPatternRouting  →  matches URL to module/action
      │
      ├── {Module}Actions::execute{Action}()  →  business logic
      │
      ├── {action}Success.php  →  view template (PHP)
      │
      └── layout.php  →  HTML decorator (wraps template output)
bash
   php test/bin/prove.php test/unit/