Because Yii is one of the fastest and most reliable PHP frameworks I use it for many web based projects. From time to time I was required to create a new view files for Yii. I decided to use a Delphi application to generate the Yii view file. Then I modified that code to generate multiple Yii Views based on values in a collection or list of strings.
When the Clone View option is selected the following dialog appears to collect the view name from the user.
Once the name is supplied the the user is then prompted to select an output folder.
Once the output folder is selected the user the view file is generated and the application is ready for the next view to be generated or to exit the application.
Output from our example may be reviewed below.
<?php /* @var $this yii\web\View */ use yii\helpers\Html; $this->title = 'About Test'; $this->params['breadcrumbs'] = $this->title; ?> <div class="site-about"> <h1><?= Html::encode($this->title) ?></h1> <p> This is the About Test page. You may modify the following file to customize its content: </p> <code><?= __FILE__ ?></code> </div>
Notice the application removes all spaces from the page name and uses that page name as the file name. The “.php” extension is also added to the file name for acceptable usage.
When I selected the Multiple Views Option the following dialog appears.
Type in as many view names as desired. For each view name listed a complete view will be created in the target sub directory.
Either click the x on the dialog or select the Exit option on the Primary Options Menu to terminate execution of dialog. The next dialog will identify the output location or views folder for the new views.
Should a view exist in the output location the following dialog will appear.
Since that file exists no output is attempted. This application will not overwrite views. Processing will resume with the next item in the list.
If you are not a Delphi developer you can still use this tool by following these instructions.
Establish a directory structure “C:\dev\w32\2016\BCSGenView” (minus double quotes). Next create a “skel” sub directory (minus double quotes). The input file is listed below. The file name should be “about.php” (minus double quotes).
<?php /* @var $this yii\web\View */ use yii\helpers\Html; $this->title = 'About'; $this->params['breadcrumbs'] = $this->title; ?> <div class="site-about"> <h1><?= Html::encode($this->title) ?></h1> <p> This is the About page. You may modify the following file to customize its content: </p> <code><?= __FILE__ ?></code> </div>
Go back to the “C:\dev\w32\2016\BCSGenView” sub directory and create a “xqt” sub directory (minus double quotes) and place the downloaded executable 32 or 64 bit there. Execute the program in the “xqt” sub directory and enjoy.
A 32 bit executable program may be downloaded by clicking here.
A 64 bit executable program may be downloaded by clicking here.
The component documentation can be found by clicking here.
The source code may be found by clicking here.
Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.