PHP code example of itcig / sagecontroller

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

    

itcig / sagecontroller example snippets



add_filter('sober/controller/path', function () {
    return dirname(get_template_directory()) . '/app/Custom-folder';
});



namespace App;

use Cig\Sage\Controller\Controller;

class Single extends Controller
{
    /**
     * Return images from Advanced Custom Fields
     *
     * @return array
     */
    public function images()
    {
        return get_field('images');
    }
}

{% if(images|length) %}
  <ul>
    {% for image in images %}
      <li><img src="{{ image.sizes.thumbnail }}" alt="{{ image.alt }}"></li>
    {% endfor %}
  </ul>
{% endif %}



namespace App;

trait Images
{
    public function images()
    {
        return get_field('images');
    }
}



namespace App;

use Cig\Sage\Controller\Controller;

class Single extends Controller
{
    use Images;
}



namespace App;

use Cig\Sage\Controller\Controller;

class Archive extends Controller
{
    public static function callback_method($arg = null)
    {
        return my_callback($arg);
    }
}

{% extends "base.twig" %}

{% block content %}
	{{ callback_method() }}
{% endblock %}



namespace App;

use Cig\Sage\Controller\Controller;
use Cig\Sage\Controller\Module\Tree;

class Single extends Controller implements Tree
{

}



namespace App;

use Cig\Sage\Controller\Controller;

class Single extends Controller
{
    protected $tree = true;
}



namespace App;

use Cig\Sage\Controller\Controller;

class App extends Controller
{
    public function siteName()
    {
        return get_bloginfo('name');
    }
}

protected $active = false;