Coder Social home page Coder Social logo

fuel-package-traitcrud's Introduction

Trait-Crud

  • Version: 1.0

Information

  • PHP >= 5.4
  • FuelPHP = 1.7/master

Description

FuelPHPのコントローラーにCRUDを提供します。

標準のscaffoldで作成されるcontrollerを共通化し、traitで提供します。 簡単なCRUDのコントローラーはより簡便な記述で実装でき、複雑なコントローラーはオーバーライド可能なメソッド群で柔軟にカスタマイズ可能です。

Install

  • git clone https://github.com/goosys/Fuel-Package-TraitCrud.git fuel/packages/trait-crud

  • vi fuel/app/config.php

      always_load => 
      	packages => 'trait-crud',
      	language => 'trait-crud'
    
  • ln -s ../../../trait-crud/views/scaffolding/trait-crud fuel/packages/oil/views/scaffolding/trait-crud

Example

Default

  • oil g scaffold/trait-crud animal name:varchar kana:varchar description:text flag:bool

  • vi fuel/app/lang/ja/model.php

      return array(
      	'animal' => array(
      		'name'   => '名称',
      		'kana'   => 'ヨミ',
      		'description'   => '説明',
      		'flag'   => 'フラグ',
      	),
      );
    
  • cp fuel/app/lang/{ja,en}/model.php

Twig

  • ln -s ../../packages/trait-crud/views/template.twig.php fuel/app/views/template.twig.php
  • oil g scaffold/trait-crud-twig animal name:varchar kana:varchar description:text flag:bool

Usage

Controller

	class Controller_Animal extends Controller_Template{
		//CRUDを提供
		use Trait_Crud;
		
		//初期化
		public function before(){
			static::$model_name       = 'Model_Animal';
			static::$controller_name  = 'Controller_Animal';
			static::$func_validate    = 'validate';
			parent::before();
		}
		
		//機能を利用
		public function action_index()
		{
			$this->_action_index();
			
			$data = array('items'=> $this->stash['models']);
			$this->template->content = View::forge('animal/index',$data);
		}
	}

Overwritable Methods

	public function _action_index(){}
	public function _action_view($id = null){}
	public function _action_create(){}
	public function _action_edit($id = null){}
	public function _action_validate(){}
	public function _action_delete($id = null){}
	
	public function _render_404(){}
	public function _render_index(){}
	public function _could_not_found_id( $params ){}
	
	public function _render_view(){}
	
	public function _set_model_from_input( $params ){}
	public function _added( $params ){}
	
	public function _could_not_save( $params ){}
	public function _validation_error( $params ){}
	public function _validated( $params ){}
	public function _render_create(){}
	
	public function _updated( $params ){}
	public function _could_not_update( $params ){}
	public function _set_model_from_validation( $params ){}
	public function _render_edit(){}
	
	public function _deleted( $params ){}
	public function _could_not_delete( $params ){}
	public function _render_delete(){}

Customize

Scaffoldのテンプレートをカスタマイズ

  • cp fuel/packages/trait-crud/views/scaffolding/trait-crud fuel/app/views/

「詳細|編集|削除」ボタンのテンプレートを編集

  • cp -r fuel/packages/trait-crud/views/include fuel/app/views/

More Information

Fuel-Package-TraitPaginationと組み合わせることで、より簡単に検索とページャー付きのCRUDが作成できます。

License

MIT License

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.