PHP code example of chemaclass / knob-base

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

    

chemaclass / knob-base example snippets


use Controllers\HomeController;

$controller = new HomeController();
$controller->getSingle('post');
 
// vendor/chemaclass/knob-base/src/models/Post.php
namespace Knob\Models;

class Post extends ModelBase
{
    public static $table = "posts";

    public function getSlug()
    {
        return $this->post_name;
    }

    public function getAuthor()
    {
        return User::find($this->post_author);
    }

    // more sentences...
}
 
// vendor/chemaclass/knob-base/src/libs/Actions.php
namespace Knob\Libs;

class Actions
{
    public static function setup()
    {
        static::adminPrintScripts();
        static::adminPrintStyles();
        static::loginView();
        static::wpBeforeAdminBarRender();
    }
    
    // rest of the implementation...
}
 
// vendor/chemaclass/knob-base/src/widgets/PagesWidget.php
namespace Knob\Widgets;

use Knob\Models\Post;

class PagesWidget extends WidgetBase
{
    public function widget($args, $instance)
    {
        $instance['pages'] = Post::getPages();
        parent::widget($args, $instance);
    }
}
 
// app/controllers/BaseController.php
namespace Controllers;

use Knob\Controllers\BaseController as KnobBaseController;

class BaseController extends KnobBaseController
{
	// more sentences...
}
 
// app/controllers/HomeController.php
namespace Controllers;

use Knob\Controllers\HomeControllerInterface;
use Models\Option;

class HomeController extends BaseController implements HomeControllerInterface {
	
    /**
     * home.php
     */
    public function getHome()
    {
        $args = [
            'posts' => Post::getAll(Option::get('posts_per_page'))
        ];
        return $this->renderPage('base/home', $args);
    }

	// rest of the implementation...
}