PHP code example of webtack / generic-controller

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

    

webtack / generic-controller example snippets



use Webtack\GenericController\TemplateController;

class AboutController extends TemplateController {
	
	/**
	 * Init templateName property from view
	 *
	 * @return string
	 */
	function templateName() {
		return "generic-about";
	}
}


Route::get(/about', ['uses' => 'AboutController@asView']);



use App\Models\Article;
use Webtack\GenericController\DetailController;

class ArticlePageController extends DetailController {
	
	/**
	 * Init Model from Query
	 *
	 * @return \Illuminate\Database\Config\Model
	 */
	function model() {
		return new Article();
	}
}


Route::get(/article/{id}', ['uses' => 'ArticlePageController@asView']);


    protected function getContextData($request, $column = []){}

protected function getContextData($request, $column = []) {
    $article = $this->model();
    $data = $article->where(['name' => 'Jhoon'])->first();
    
    return ['article' => $data];
}


public function get($request, $name) {
	$context = $this->getContextData($request, ['name' => $name]);
	return $this->renderToResponse($context);
}


    public function get($request);
    public function post($request);
    public function put($request);
    public function delete($request);
    public function path($request);
    public function options($request);


{{ $article->title }}


protected function contextObjectName() {
    return "foobar";
}



use Webtack\GenericController\ListController;

class BlogPageController extends ListController {
	
	/**
	 * @return \Illuminate\Database\Config\Model
	 */
	public function model() {
		return new Blog();
	}
	
	/**
	 * Init templateName from view
	 *
	 * @return string
	 */
	public function templateName() {
		return 'blog';
	}
	
	protected function templatePrefix() {
		return 'blog.';
	}
}


Route::get(/blog', ['uses' => 'BlogPageController@asView']);