Code generation with logic-less templates for Yii

Overview

Caviar

Code generation with logic-less templates for Yii.

Caviar vs Gii

You might be wondering why you should use Caviar instead of Gii, so let us take a look at how they differ from each other.

The main disadvantage with Gii is that it is troublesome to write templates for it. Have you ever looked at one of its templates? If you have you know that they are quite hard to read. Compare the following template in Gii to the corresponding template in Caviar.

Caviar uses plain text (.txt files) templates, which are compiled into php files to apply separation of concerns. This means that all logic must be contained in the generator and that only strings can be passed to the template. Instead of doing logical operations within the template we do them in the generator when we create the data for the template. You can take a look at the model generator for an example on this.

Convinced? Follow the instructions below to install Caviar.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist crisu83/yii-caviar "*"

or add

"crisu83/yii-caviar": "*"

to the require section of your composer.json file.

Usage

Add the a command to your console application configuration:

return array(
  ...
  'commandMap' => array(
    'generate' => array(
      'class' => '\crisu83\yii_caviar\Command',
      'basePath' => '
   
    '
   ,
    ),
    ...
  ),
);

When that is done you can use it to generate code:

yiic generate generator [context:]subject [options]

Where generator is the name of the generator, context is the name of your application (e.g. app) and subject is a name for the item that will be generated.

You can view the command help by running the following command:

yiic generate help

Or the help for a particular generator by appending -t (or --help) to your command:

yiic generate component --help

Disable namespaces

Caviar uses namespaces by default, mainly because it has a proven to be a good practice in large scale applications, but it also allows you to easily disable namespaces for all generators.

Disabling namespaces for all generators can easily be done by adding the following to your configuration:

'generate' => array(
  ...
  'defaultTemplate' => 'noNamespaces',
  'enableNamespaces' => false,
  'templates' => array(
    'noNamespaces' => '
   
    /templates/no-namespaces'
   ,
  ),
)

Fancy UI

Caviar has a fancy UI, here are a few screenshots showing the UI.

Generators

The following generators are already supported:

  • component
  • config
  • controller
  • layout
  • model
  • view
  • webapp

The following generators are planned to be included in the first release:

  • action
  • crud
  • widget
You might also like...
An enhanced Yii 2 widget encapsulating the HTML 5 range input (sub repo split from yii2-widgets)
An enhanced Yii 2 widget encapsulating the HTML 5 range input (sub repo split from yii2-widgets)

yii2-widget-rangeinput The RangeInput widget is a customized range slider control widget based on HTML5 range input. The widget enhances the default H

Extension for creating and sending emails for the Yii PHP framework.

yii-emailer Extension for creating and sending emails for the Yii PHP framework. Usage Migrate the email_message database table by this command: yiic

This extension provides Flysystem integration for the Yii framework

This extension provides Flysystem integration for the Yii framework. Flysystem is a filesystem abstraction which allows you to easily swap out a local filesystem for a remote one.

Password strategies for Yii

Password strategies are specifications for how passwords should be encoded and verified and how complicated user supplied passwords should be.

Slim Framework using Jade for templates

Welcome to Slim-Jade What? This is a boilerplate. It's the Slim Framework with jade.php to render views Why? I like the Sinatra style MVC and love Jad

Mind is the PHP code framework designed for developers. It offers a variety of solutions for creating design patterns, applications and code frameworks.
Mind is the PHP code framework designed for developers. It offers a variety of solutions for creating design patterns, applications and code frameworks.

Mind Mind is the PHP code framework designed for developers. It offers a variety of solutions for creating design patterns, applications and code fram

Low-code Framework for Web Apps in PHP
Low-code Framework for Web Apps in PHP

Agile UI - User Interface framework for Agile Toolkit Agile Toolkit is a Low Code framework written in PHP. Agile UI implement server side rendering e

Source code of Ice framework
Source code of Ice framework

Ice framework Simple and fast PHP framework delivered as C-extension. Stage How to contribute? Fork the ice/framework repository. Create a new branch

A lightweight solution for running code concurrently in PHP
A lightweight solution for running code concurrently in PHP

A lightweight solution for running PHP code concurrently This package makes it easy to run PHP concurrently. Behind the scenes, concurrency is achieve

Comments
  • yii-caviar & yii-app

    yii-caviar & yii-app

    I have seen that this is beta, but is it supposed to work out-of-the box with yii-app? I am getting this error:

    test@user1:/var/www/app$ php yiic generate -h PHP Error[2]: include(Command.php): failed to open stream: No such file or directory in file /var/www/vendor/yiisoft/yii/framework/YiiBase.php at line 432 #0 /var/www/vendor/yiisoft/yii/framework/YiiBase.php(432): autoload() #1 unknown(0): autoload() #2 /var/www/vendor/yiisoft/yii/framework/YiiBase.php(204): spl_autoload_call() #3 /var/www/vendor/yiisoft/yii/framework/console/CConsoleCommandRunner.php(173): createComponent() #4 /var/www/vendor/yiisoft/yii/framework/console/CConsoleCommandRunner.php(67): CConsoleCommandRunner->createCommand() #5 /var/www/vendor/yiisoft/yii/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run() #6 /var/www/vendor/yiisoft/yii/framework/base/CApplication.php(184): CConsoleApplication->processRequest() #7 /var/www/app/yiic.php(21): CConsoleApplication->run() #8 /var/www/app/yiic(4): require_once()

    The path is set like this in the console config: 'generate' => array( 'class' => 'vendor.crisu83.yii-caviar.Command', 'basePath' => DIR . '/../../', ),

    Just for finding out what is wrong, I have tried to vendor.crisu83.yii-caviar.Command2 which is of course not existing. That throws a complete different error (path not valid). So this means that the vendor.crisu83.yii-caviar.Command is found, but something else throws the error.

    opened by gb5256 4
Owner
Christoffer Niska
Technical Lead at Tesseract, father of many, polyglot programmer, open source enthusiast, TypeScript Ninja.
Christoffer Niska
This extension provides a view renderer for Pug templates for Yii framework 2.0 applications.

This extension provides a view renderer for Pug templates for Yii framework 2.0 applications.

Revin Roman 9 Jun 17, 2022
This Slim Framework middleware will compile LESS CSS files on-the-fly using the Assetic library

This Slim Framework middleware will compile LESS CSS files on-the-fly using the Assetic library. It supports minification and caching, also via Asseti

Gerard Sychay 22 Mar 31, 2020
Yii 2: The Fast, Secure and Professional PHP Framework

Yii 2 is a modern framework designed to be a solid foundation for your PHP application. It is fast, secure and efficient and works right out of the bo

Yii Software 14k Dec 31, 2022
Yii 2 Bootstrap 5 Extension

Twitter Bootstrap 5 Extension for Yii 2 This is the Twitter Bootstrap extension for Yii framework 2.0. It encapsulates Bootstrap 5 components and plug

Yii Software 48 Dec 14, 2022
Yii-specific middleware

Yii Middleware The package ... Requirements PHP 8.0 or higher. Installation The package could be installed with composer: composer require yiisoft/yii

Yii Software 9 Nov 4, 2022
Yii2-symfonymailer - Yii 2 Symfony mailer extension.

Yii Mailer Library - Symfony Mailer Extension This extension provides a Symfony Mailer mail solution for Yii framework 2.0. For license information ch

Yii Software 28 Dec 22, 2022
Yii 2 widget for the Froala WYSIWYG HTML Editor.

Yii Framework Froala WYSIWYG HTML Editor Yii 2 widget for Froala Wysiwyg editor. Installation The preferred way to install this extension is through c

Froala 99 Sep 21, 2022
Geography module for Yii 2

Geography module for Yii 2

Sergey Fedorov 13 Oct 20, 2018
Extends Yii Menu widget

Extends Yii Menu widget. This widget offers a scrollspy and affixed enhanced navigation (upto 2-levels) to highlight sections and secondary sections in each page.

Kartik Visweswaran 15 Mar 12, 2022
DepDrop widget is a Yii 2 wrapper for the dependent-dropdown jQuery plugin by Krajee.

yii2-widget-depdrop The DepDrop widget is a Yii 2 wrapper for the dependent-dropdown jQuery plugin by Krajee. This plugin allows multi level dependent

Kartik Visweswaran 82 Nov 27, 2022