webtack/generic-controller 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webtack/generic-controller

Composer 安装命令:

composer require webtack/generic-controller

包简介

Generic Controllers includes a set of generic representations that are ideally suited for solving a number of routine tasks.

README 文档

README

Generic Controllers is a extension system for your Laravel application.
Generic Controllers includes a set of generic representations that are ideally suited for solving a number of routine tasks.

Installation

Install using composer:

composer require webtack/generic-controller

Simple examples

Use Generic as the parent classes. You can specify these classes as the parent for your custom view class and override the attribute values in the body of your class

TemplateController

Suitable for displaying static pages that do not receive data from the database.

use Webtack\GenericController\TemplateController;

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

Create a router and call the method in it @asView

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

DetailController

It should be used when you want to get one model for a given key

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();
	}
}

Create a router and call the method in it @asView

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

Context data

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

The method responsible for obtaining data from the database.
By default, there will be an attempt to get the model by the parameter id from the route

But you can override this behavior by overloading this method. It must return an array with a context name key and an object of the model.

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

Or override get method

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

Supported methods correspond to request types.

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

All methods accept the first object \Illuminate\Http\Request $request The following parameters can be those that you defined in your routes.

View Name

By default, DetailController will search for a view with the name of the "article-page" class new, and you will also be able to override it in the templateName method

Note the auxiliary methods templatePrefix and templateSuffix.
If you define them, the data will be appended to the name of the view returned by the method templateName

Context name

The name of the access variable in the view will be taken from the name of the model class starting with a small letter.

{{ $article->title }}

Of course you can override this in method contextObjectName

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

ListController

Use to display the list of entities

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.';
	}
}

Create a router and call the method in it @asView

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

By default, the name of the view will be appended with the suffix - list, but you can undo or override this behavior in the corresponding method, of course.

P.S.

This is a small set of possibilities. But I think in the future I will expand it if necessary.

webtack/generic-controller 适用场景与选型建议

webtack/generic-controller 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 132 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「controller」 「laravel」 「generic」 「webtack」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 webtack/generic-controller 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 webtack/generic-controller 我们能提供哪些服务?
定制开发 / 二次开发

基于 webtack/generic-controller 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 132
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-04