Code Monkey home page Code Monkey logo

yii-gii's Introduction

Yii

Gii Extension for Yii


Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality Code Coverage Mutation testing badge static analysis

This extension provides a Web-based code generator, called Gii, for Yii framework applications. You can use Gii to quickly generate models, forms, modules, CRUD, etc.

Requirements

  • PHP 8.1 or higher.

Installation

The package could be installed with Composer:

composer require yiisoft/yii-gii

General usage

Once the extension is installed, simply modify your application configuration as follows:

return [
    'bootstrap' => ['gii'],
    'modules' => [
        'gii' => [
            'class' => Yiisoft\Yii\Gii\Gii::class,
        ],
        // ...
    ],
    // ...
];

You can then access Gii through the following URL:

http://localhost/path/to/index.php?r=gii

or if you have enabled pretty URLs, you may use the following URL:

http://localhost/path/to/index.php/gii

Using the same configuration for your console application, you will also be able to access Gii via command line as follows,

# change path to your application's base path
cd path/to/AppBasePath

# show help information about Gii
yii help gii

# show help information about the model generator in Gii
yii help gii/model

# generate City model from city table
yii gii/model --tableName=city --modelClass=City

Documentation

If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.

License

The Gii Extension for Yii is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

yii-gii's People

Contributors

arhell avatar arogachev avatar dependabot-preview[bot] avatar dependabot[bot] avatar devanych avatar fantom409 avatar hamrak avatar hiqsol avatar luizcmarin avatar machour avatar pistej avatar roxblnfk avatar rustamwin avatar samdark avatar silverfire avatar softark avatar stylecibot avatar terabytesoftw avatar viktorprogger avatar vjik avatar xepozz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii-gii's Issues

Incompatible with validator 2.0

What steps will reproduce the problem? Using composer update

What is the expected result? An update

What do you get instead? Unable to update

Additional info

Q A
Version 1.0.?
PHP version 8.1.13
Operating system Windows 11

Call getName() on array

What steps will reproduce the problem?

composer.json:

{
    "minimum-stability": "dev",
    "require": {
        "yiisoft/yii-base-web": "^3.0@dev",
        "yiisoft/yii-dataview": "^3.0@dev",
        "yiisoft/yii-bootstrap4": "^3.0@dev",
        "yiisoft/yii-jquery": "^3.0@dev",
        "yiisoft/yii-console": "^3.0@dev",
        "yiisoft/cache": "^3.0@dev",
        "yiisoft/di": "^3.0@dev",
        "yiisoft/log": "^3.0@dev",
        "yiisoft/rbac": "^3.0@dev",
        "yiisoft/view": "^3.0@dev",
        "yiisoft/db": "^3.0@dev",
        "yiisoft/db-mysql": "^3.0@dev",
        "yiisoft/yii-cli": "^3.0@dev",
        "yiisoft/yii-gii": "^3.0@dev"
    },
    "require-dev": {
        "foxy/foxy": "^1.0",
        "yiisoft/yii-debug": "^3.0@dev",
        "hiqdev/composer-config-plugin": "^1.0@dev"
    },
    "extra": {
        "branch-alias": {
            "dev-master": "3.0.x-dev"
        },
        "config-plugin": {
            "common": "config/common.php",
            "params": "config/params.php",
            "web": "config/web.php",
            "console": "config/console.php"
        }
    },
    "autoload": {
      "psr-4": {
        "app\\": "app/"
      }
    }
}

./yii:

#!/usr/bin/env php
<?php

use hiqdev\composer\config\Builder;
use yii\di\Container;
use yii\helpers\Yii;

(function () {
    require_once __DIR__ . '/vendor/autoload.php';

    $container = new Container(require Builder::path('console'));

    Yii::setContainer($container);

    $container->get('app')->run();
})();

config/console.php:

<?php
return [
    'app' => [
        'controllerNamespace' => app\command::class,
        'controllerMap' => [
            'migrate' => [
                'migrationPath' => 'config/migration',
            ],
        ],
        'bootstrap' => ['gii'],
        'modules' => [
            'gii' => [
                '__class' => yii\gii\Module::class,
            ],
        ],
    ],
];

run ./yii in console

What's expected?

list of commands including gii/*

What do you get instead?

Exception 'Error' with message 'Call to a member function getName() on array' in /home/me/code/yii3/vendor/yiisoft/yii-gii/src/console/GenerateController.php:148

Additional info

Q A
Yii version 3.0.0-dev
PHP version 7.3.2
Operating system Linux / Manjaro

Call to a member function getDescription() on array

What steps will reproduce the problem?

$ git clone https://github.com/yiisoft/yii-project-template

composer.json:

{
	"name": "yiisoft/yii-project-template",
	[...]
	"require": {
		"yiisoft/yii-dataview": "^3.0@dev",
		"yiisoft/yii-bootstrap4": "^3.0@dev",
		"yiisoft/yii-jquery": "^3.0@dev",
		"yiisoft/yii-console": "^3.0@dev",

		"yiisoft/yii-base-web": "^3.0@dev",

		"yiisoft/cache": "^3.0@dev",
		"yiisoft/di": "^3.0@dev",
		"yiisoft/log": "^3.0@dev",
		"yiisoft/rbac": "^3.0@dev",
		"yiisoft/view": "^3.0@dev"
	},
	"require-dev": {
		"foxy/foxy": "^1.0",
		"yiisoft/yii-debug": "^3.0@dev",
		"yiisoft/yii-gii": "^3.0@dev",
		"hiqdev/composer-config-plugin": "^1.0@dev"
	},
	"extra": {
		"config-plugin": {
			"common": "config/common.php",
			"params": "config/params.php"
		}
	}
}

What's expected?

I expect to see the help description of the gii/model help (or any other command)

What do you get instead?

The error in subject: "Call to a member function getDescription() on array"

Additional info

Inspecting better the code, I see the error is generaten by this line 161 in src/console/GenerateController:

$description = $action->generator->getDescription();

and infact, as the error says, $action->generator is really an array.

I suspect this error comes from the GenerateController not implementing Initiable interface, because I see in code that the conversion from generator array to object would be done inside GenerateController::init(), but this method is never called.

Q A
Yii version 3.0.x@dev
PHP version 7.1.26
Operating system Sabayon Linux

Simple property mapper for ActiveRecord.

It would be great if the generated ActiveRecord had a property mapper. That is, create_at was mapped to createAt.
For example like this:

public function getAttributeMap(): array
{
    return [
        'createAt' => 'create_at',
    ];
}

public function __get(string $name)
{
    return parent::__get($this->getAttributeMap()[$name] ?? $name);
}

public function __set(string $name, $value): void
{
    parent::__set($this->getAttributeMap()[$name] ?? $name, $value);
}

public function __isset(string $name): bool
{
    return parent::__isset($this->getAttributeMap()[$name] ?? $name);
}

public function __unset(string $name): void
{
    return parent::__unset($this->getAttributeMap()[$name] ?? $name);
}

@property will be appropriate.

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - Installation request for yiisoft/view ^3.0@dev -> satisfiable by yiisoft/view[3.0.x-dev].
    - yiisoft/view 3.0.x-dev requires psr/event-dispatcher-implementation 1.0.0 -> no matching package found.
  Problem 2
    - Installation request for yiisoft/yii-web ^3.0@dev -> satisfiable by yiisoft/yii-web[3.0.x-dev].
    - yiisoft/yii-web 3.0.x-dev requires psr/http-factory-implementation 1.0 -> no matching package found.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
 - It's a private package and you forgot to add a custom repository to find it

Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Invalid config

What steps will reproduce the problem?

Install this package with a composer

What is the expected result?

Gii will be auto-discovered by CLI app, so

./vendor/bin/yii 

echos

... 
 gii/controller        Gii controller generator
...

What do you get instead?

Gii command is not registered and is not listed as an available command

Additional info

The issue is in the wrong config key name:
Actual

'console' => [
        'commands' => [
            'gii/controller' => ControllerCommand::class,
        ],
    ],

Expected

'yiisoft/yii-console' => [
        'commands' => [
            'gii/controller' => ControllerCommand::class,
        ],
    ],
Q A
Version 1.0.?
PHP version
Operating system

[RFC] Redesign

Architecture design now looks like:

  • All logic in one class:
    • "Loading" parameters into Generators made as with forms
    • Validation placed inside Generators
    • Preview and action placed inside Generators
  • Each Generator extends BaseGenerator that contains a lot of common logic
  • Separated templates files
  • Console and web api supported quite good

I want to suggest to refactor it a bit:

  • Move out data classes from Generators
  • Move validation rules to that data classes
  • Use composition instead of inheritance in Generators
  • Remove preview action and replace it with in-memory storage
  • Use command + handler pattern for Generators and their data classes. So we will have stateless handler and stateful command (data class)
  • Use the validator's feature dumping validation rules for exposing Generators parameters for API and Console (if it's possible and cheap)

Whole concept is similar to validator's.

Consider if `GiiInterface::addGenerator()` is needed

Gii generators are now passed through Gii class constructor. Any 3rd party libraries can add their own generators by declaring the needed section in its' configs.

Seems that GiiInterface::addGenerator() won't be used.

In case it's needed GiiInterface::addGenerator() must support lazy generator type: Closure(): GeneratorInterface

Make Gii accessible via Restful API

Right now you have to use Forms to submit information in Gii. That is good, but it would be better if we could do code generation via an API. That will remove the need for Tools (IDEs et al) to be able to generate things using their own “forms” and just POST to API, than now when you have to use ./yii for generating codes automatically.

Using ./yii in code generation is difficult (you have to manage the launched process on different thread to avoid blocking the UI which adds overhead). Also managing response message especially in case of error is difficult.

My Proposal is:
1. Move all Gii functionalities to REST API
2. The current UI should be only a front end to that API

The Topic was discussed here before this issue was opened

API Generator (Feature request)

This is feature request for 3.0. I wondered about having Gii include an API generator/Template. I think Gii is great! But I haven't been able to see a way to generate a base API. But something that could analyse models and relations as Gii does and then create potentially Repository Pattern or JSON API style or similar based off those would be a cool concept. Spring has something similar where you can use their starter wizard in combination with JPA to generate entities etc.

No worries, if you don't think this is a good idea 🙂

Separate Core and Command-line into separate package

Currently when you install Gii, it installs a lot of dependencies,
like view. In many cases it might be okay, but in some cases like in API, these dependencies are not desirable. It would be nice if you could only use command-line with core of Gii without all these extra dependencies.

Project yiisoft/demo failed to add yiisoft/yii-gii

What steps will reproduce the problem?

composer create-project yiisoft/demo --prefer-dist --stability=dev
composer update
composer require --prefer-dist yiisoft/yii-gii

What is the expected result?

run from command line yii with gii

What do you get instead?

% php yii

Fatal error: Uncaught ErrorException: Duplicate key "Yiisoft\Rbac\StorageInterface" in configs:
 - config/packages/yiisoft/yii-gii/$common in /usr/home/dev/yii3/test/vendor/yiisoft/config/src/Config.php:379
Stack trace:
#0 /usr/home/dev/yii3/test/vendor/yiisoft/config/src/Config.php(250): Yiisoft\Config\Config->throwException('Duplicate key "...')
#1 /usr/home/dev/yii3/test/vendor/yiisoft/config/src/Config.php(114): Yiisoft\Config\Config->merge(Array, '', Array, Array)
#2 /usr/home/dev/yii3/test/vendor/yiisoft/config/src/Config.php(82): Yiisoft\Config\Config->buildGroup('console', '/')
#3 /usr/home/dev/yii3/test/src/Runner/ConsoleApplicationRunner.php(50): Yiisoft\Config\Config->get('console')
#4 /usr/home/dev/yii3/test/yii(25): App\Runner\ConsoleApplicationRunner->run()
#5 {main}
  thrown in /usr/home/dev/yii3/test/vendor/yiisoft/config/src/Config.php on line 379

Additional info

Q A
Version 3.0.x-dev
PHP version PHP 8.0.10
Operating system FreeBSD domainName 12.2-RELEASE FreeBSD 12.2-RELEASE r366954 GENERIC amd64

To solve the problem I just commented one line:

% diff -urNa -U10 ../test2/config/packages/merge_plan.php config/packages/merge_plan.php 
--- ../test2/config/packages/merge_plan.php	
+++ config/packages/merge_plan.php	
@@ -86,21 +86,21 @@
         ],
         'console' => [
             '/' => [
                 '$common',
                 'config/console/*.php',
             ],
             'yiisoft/yii-cycle' => [
                 'console.php',
             ],
             'yiisoft/yii-gii' => [
-                '$common',
+//                '$common',
                 'console.php',
             ],
             'yiisoft/translator-extractor' => [
                 'console.php',
             ],
             'yiisoft/yii-console' => [
                 'console.php',
             ],
             'yiisoft/yii-event' => [
                 'console.php',

I believe it is due to the duplication in composer.json:

% grep -B5 -A5 '\$common' vendor/yiisoft/yii-gii/composer.json
            "source-directory": "config"
        },
        "config-plugin": {
            "params": "params.php",
            "console": [
                "$common",
                "console.php"
            ],
            "common": "common.php"
        }
    },

Any other suggestions for fixing the problem? or would this fix be recommended?

[Enh] migration generation

An interface to use the migrate/create console command would be great, specially to generate the fields.

download unrelated npm meta file

    "require": {
        "npm-asset/typeahead.js": "0.10.* | ~0.11.0"
    },

Crazily write a lot of useless npm json file

The reason is that

"npm-asset/typeahead.js": "~0.11.0"

composer.json

{
    "name": "yiisoft/yii-project-template",
    "type": "project",
    "description": "Yii Framework Project Template",
    "keywords": [
        "yii",
        "app",
        "project",
        "template"
    ],
    "homepage": "https://github.com/yiisoft/yii-project-template",
    "license": "BSD-3-Clause",
    "support": {
        "source": "https://github.com/yiisoft/yii-project-template",
        "issues": "https://github.com/yiisoft/yii-project-template/issues",
        "wiki": "https://github.com/yiisoft/yii-project-template/wiki",
        "forum": "http://www.yiiframework.com/forum/"
    },
    "authors": [
        {
            "name": "Qiang Xue",
            "role": "Founder and project lead",
            "email": "[email protected]",
            "homepage": "http://www.yiiframework.com/"
        },
        {
            "name": "Alexander Makarov",
            "role": "Core framework development",
            "email": "[email protected]",
            "homepage": "http://rmcreative.ru/"
        },
        {
            "name": "Maurizio Domba",
            "role": "Core framework development",
            "homepage": "http://mdomba.info/"
        },
        {
            "name": "Carsten Brandt",
            "role": "Core framework development",
            "email": "[email protected]",
            "homepage": "http://cebe.cc/"
        },
        {
            "name": "Paul Klimov",
            "role": "Core framework development",
            "email": "[email protected]"
        },
        {
            "name": "Dmitry Naumenko",
            "role": "Core framework development",
            "email": "[email protected]"
        },
        {
            "name": "Boudewijn Vahrmeijer",
            "role": "Core framework development",
            "email": "[email protected]",
            "homepage": "http://dynasource.eu"
        }
    ],
    "require": {
        "npm-asset/typeahead.js": "~0.11.0"
    },
    "require-dev": {
    },
    "extra": {
        "branch-alias": {
            "dev-master": "3.0.x-dev"
        }
    },
    "minimum-stability": "dev",
    "repositories": [
        {
            "type": "composer",
            "url": "https://asset-packagist.org"
        }
    ]
}

Config input and watch mode

It would be great to have an ability to configure multiple generators in a single config file and have a watch mode — when the config changes, gii regenerates the code.

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.