2017 © Pedro Peláez
 

library giic

Toolset for running Gii on the command line

image

schmunk42/giic

Toolset for running Gii on the command line

  • Friday, October 10, 2014
  • by schmunk
  • Repository
  • 4 Watchers
  • 4 Stars
  • 2,313 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 5 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

giic

This package provides a toolset for running Gii on the command line. It runs an unlimited number of pre-configured Gii Generator templates., (*1)

Introduction

"I have configured several templates and with Gii I create the code for modules by selecting the templates that is associated with the DB-table. It is working great and saves me lots of time. If I can bash-script or php-script it, it would be awesome.", (*2)

"Currently it's not possible and, I'm afraid, will not be possible during all your prototyping stage. ", (*3)

unixjunky and Samdark, 2010, (*4)

But we made it work!, (*5)

How does it work?

Giic wraps the Generator and Gii-module in a GiicApplication, which is funky mixture of CConsoleApplication and CWebApplication., (*6)

You can use a custom config file to specify your input parameters. Every action corresponds to a click on the Generate button in the web-frontend. Just specify the model attributes as you'd have done in the web application. For more details follow the link in the 'Confiugration' section., (*7)

Note: This code is experimental, please make a backup before using it in a project. If you find an issue, please report it here., (*8)

Resources

Installation

via composer

composer.phar require schmunk42/giic

Usage

php vendor/schmunk42/giic/giic.php giic generate alias.to.giic-config

Setup

Giic can be installed in any application, but to get a better impression how it works, we'll guide you through a sample setup with an Yii extension which features CRUDs for the MySQL demo database Sakila., (*9)

For the test-drive, we'll install Phundament together with the Sakila Demo module schmunk42/yii-sakila-crud This module provides migrations and configurations for the MySQL demo database "Sakila" to use with giic. It also includes the generated CRUDs to play around with., (*10)

Install a development(!) version Phundament and the demo extension:, (*11)

composer.phar create-project -sdev phundament/app app-crud-test
cd app-crud-test
composer.phar require schmunk42/yii-sakila-crud:@dev

Hint: Standard gii-template-collection usage is preconfigured in Phundament., (*12)

Add sakila migrations to app/config/console-local.php:, (*13)

'import' => array(
    'vendor.phundament.gii-template-collection.components.*'
),
'aliases' => array(
    'sakila' => 'vendor.schmunk42.yii-sakila-crud.*'
),    
'commandMap' => array(
    'migrate' => array(
        // enable eg. data migrations for your local machine
        'modulePaths' => array(
            'sakila'  => 'vendor.schmunk42.yii-sakila-crud.migrations',
        ),
    ),
),

Add sakila module and MySQL database to app/config/main-local.php:, (*14)

'modules' => array(
    'sakila' => array(
        'class' => 'vendor.schmunk42.yii-sakila-crud.SakilaModule'
    )
),
'components' => array(
    'db'            => array(
        'tablePrefix'      => '',
        'connectionString' => 'mysql:host=localhost;dbname=giic',
        'emulatePrepare'   => true,
        'username' => 'test',
        'password' => 'test',
        'charset'  => 'utf8',
    ),
)

Run the migrations to setup the database:, (*15)

app/yiic migrate

Because Yii can only create CConsoleApplications we have to use the supplied CLI entry-script to create our hybrid application. Run the following command to invoke the set configured actions:, (*16)

php vendor/schmunk42/giic/giic.php giic generate sakila

Your console output should look similar to this., (*17)

Open http://localhos/app-crud-test/www/index.php?r=sakila to checkout your CRUDs. Login with admin / admin., (*18)

Bonus: giix

The config file also looks for giix generators in application.extensions.giix, you may download giix and place it into extensions., (*19)

Configuration

"The big one" - actions for generating two types of models (gtc & giix) and four types of CRUDs into five different locations., (*20)

See the Sakila Configuration checkout the comments for an explanation., (*21)

Troubleshooting

  • Watch out for XSLT bugs, eg. Entity: line 134: parser error : EntityRef: expecting ';' / Entity nbsp not defined / ...
  • If you don't get any errors or output, check your generator templates in your browser in gii
  • Set file permission to 777 in /app/runtime/gii-1.1.13
  • run composer.phar update to get the latest packages

Glitches

  • All output files are overwritten by default with, (*22)

    define('GIIC_ALL_CONFIRMED', true);, (*23)

Patch your code model (GiixModelCode, GiixCrudCode), override this method:, (*24)

public function confirmed($file)
{
    if (defined('GIIC_ALL_CONFIRMED') && GIIC_ALL_CONFIRMED === true) {
        return true;
    } else {
        return parent::confirmed($file);
    }
}

Note: You'll have to patch existing extensions like eg. giix, (*25)

Help is very welcome, send us a Pull Request!, (*26)

Tested Generators

The Versions

10/10 2014

dev-master

9999999-dev https://github.com/schmunk42/giic

Toolset for running Gii on the command line

  Sources   Download

BSD-3-Clause

The Requires

 

gii cli yii

10/10 2014

0.1.4

0.1.4.0 https://github.com/schmunk42/giic

Toolset for running Gii on the command line

  Sources   Download

BSD-3-Clause

The Requires

 

gii cli yii

01/10 2013

0.1.3

0.1.3.0 https://github.com/schmunk42/giic

Toolset for running Gii on the command line

  Sources   Download

BSD-3-Clause

The Requires

 

gii cli yii

20/09 2013

0.1.2

0.1.2.0 https://github.com/schmunk42/giic

Toolset for running Gii on the command line

  Sources   Download

BSD-3-Clause

The Requires

 

gii cli yii

19/08 2013

0.1.1

0.1.1.0 https://github.com/schmunk42/giic

Toolset for running Gii on the command line

  Sources   Download

BSD-3-Clause

The Requires

 

gii cli yii

01/08 2013

0.1.0

0.1.0.0 https://github.com/schmunk42/giic

Gii from the CLI

  Sources   Download

BSD-3-Clause

The Requires

 

components phundament