├── .bowerrc ├── .gitignore ├── LICENSE.md ├── README.md ├── assets └── AppAsset.php ├── commands └── HelloController.php ├── composer.json ├── composer.lock ├── config ├── console.php ├── db.php ├── params.php └── web.php ├── controllers ├── ReceiptController.php └── SiteController.php ├── mail └── layouts │ └── html.php ├── migrations └── m150204_103949_create_receipt_tables.php ├── models ├── ContactForm.php ├── LoginForm.php ├── Receipt.php ├── ReceiptDetail.php └── User.php ├── requirements.php ├── runtime └── .gitignore ├── tests ├── README.md ├── codeception.yml └── codeception │ ├── .gitignore │ ├── _bootstrap.php │ ├── _output │ └── .gitignore │ ├── _pages │ ├── AboutPage.php │ ├── ContactPage.php │ ├── LoginPage.php │ └── ReceiptPage.php │ ├── acceptance.suite.yml │ ├── acceptance │ ├── AboutCept.php │ ├── ContactCept.php │ ├── HomeCept.php │ ├── LoginCept.php │ ├── ReceiptCept.php │ └── _bootstrap.php │ ├── bin │ ├── _bootstrap.php │ ├── yii │ └── yii.bat │ ├── config │ ├── acceptance.php │ ├── config.php │ ├── functional.php │ └── unit.php │ ├── fixtures │ └── .gitignore │ ├── functional.suite.yml │ ├── functional │ ├── AboutCept.php │ ├── ContactCept.php │ ├── HomeCept.php │ ├── LoginCept.php │ └── _bootstrap.php │ ├── templates │ └── .gitignore │ ├── unit.suite.yml │ └── unit │ ├── _bootstrap.php │ ├── fixtures │ ├── .gitkeep │ └── data │ │ └── .gitkeep │ ├── models │ ├── ContactFormTest.php │ ├── LoginFormTest.php │ └── UserTest.php │ └── templates │ └── fixtures │ └── .gitkeep ├── views ├── layouts │ └── main.php ├── receipt │ ├── _form.php │ ├── create.php │ ├── index.php │ ├── update.php │ └── view.php └── site │ ├── about.php │ ├── contact.php │ ├── error.php │ ├── index.php │ └── login.php ├── web ├── assets │ └── .gitignore ├── css │ └── site.css ├── favicon.ico ├── index-test.php ├── index.php └── robots.txt ├── yii └── yii.bat /.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory" : "vendor/bower" 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # phpstorm project files 2 | .idea 3 | 4 | # netbeans project files 5 | nbproject 6 | 7 | # zend studio for eclipse project files 8 | .buildpath 9 | .project 10 | .settings 11 | 12 | # windows thumbnail cache 13 | Thumbs.db 14 | 15 | # composer vendor dir 16 | /vendor 17 | 18 | # composer itself is not needed 19 | composer.phar 20 | 21 | # Mac DS_Store Files 22 | .DS_Store 23 | 24 | # phpunit itself is not needed 25 | phpunit.phar 26 | # local phpunit config 27 | /phpunit.xml 28 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The Yii framework is free software. It is released under the terms of 2 | the following BSD License. 3 | 4 | Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com) 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | * Neither the name of Yii Software LLC nor the names of its 18 | contributors may be used to endorse or promote products derived 19 | from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Yii2 Dynamic Tabular Form App 2 | ================================ 3 | 4 | This is a Demonstration on how to implement dynamic tabular forms. 5 | This application is built on top of [Yii2 Basic application template](https://github.com/yiisoft/yii2-app-basic). 6 | Please refer to the basic app for more installation details and requirements such as composer 7 | The dynamic addition of rows in this app does not actually implement javascript and instead uses a `addRow` button to refresh the page with a new row 8 | 9 | 10 | Receipt Controller 11 | ------------ 12 | 13 | After installation: 14 | - run the migration using 15 | ``` 16 | php yii migrate 17 | ``` 18 | - Access the receipt CRUD in 19 | ``` 20 | http://localhost/yii2-dynamic-tabular-form-app/web/?r=receipt 21 | ``` 22 | 23 |  24 | 25 | Running Tests 26 | ----------- 27 | Requirements 28 | - Firefox 29 | - Selenium 30 | 31 | Configuration 32 | modify the `tests/codeception/acceptance.suite.yml` 33 | ``` 34 | config: 35 | WebDriver: 36 | url: 'http://127.0.0.1/yii2-dynamic-tabular-form-app/web/' 37 | browser: firefox 38 | restart: true 39 | clear_cookies: true 40 | ``` 41 | with your necessary settings 42 | -------------------------------------------------------------------------------- /assets/AppAsset.php: -------------------------------------------------------------------------------- 1 | 14 | * @since 2.0 15 | */ 16 | class AppAsset extends AssetBundle 17 | { 18 | public $basePath = '@webroot'; 19 | public $baseUrl = '@web'; 20 | public $css = [ 21 | 'css/site.css', 22 | ]; 23 | public $js = [ 24 | ]; 25 | public $depends = [ 26 | 'yii\web\YiiAsset', 27 | 'yii\bootstrap\BootstrapAsset', 28 | ]; 29 | } 30 | -------------------------------------------------------------------------------- /commands/HelloController.php: -------------------------------------------------------------------------------- 1 | 18 | * @since 2.0 19 | */ 20 | class HelloController extends Controller 21 | { 22 | /** 23 | * This command echoes what you have entered as the message. 24 | * @param string $message the message to be echoed. 25 | */ 26 | public function actionIndex($message = 'hello world') 27 | { 28 | echo $message . "\n"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yiisoft/yii2-app-basic", 3 | "description": "Yii 2 Basic Application Template", 4 | "keywords": ["yii2", "framework", "basic", "application template"], 5 | "homepage": "http://www.yiiframework.com/", 6 | "type": "project", 7 | "license": "BSD-3-Clause", 8 | "support": { 9 | "issues": "https://github.com/yiisoft/yii2/issues?state=open", 10 | "forum": "http://www.yiiframework.com/forum/", 11 | "wiki": "http://www.yiiframework.com/wiki/", 12 | "irc": "irc://irc.freenode.net/yii", 13 | "source": "https://github.com/yiisoft/yii2" 14 | }, 15 | "minimum-stability": "dev", 16 | "require": { 17 | "php": ">=5.4.0", 18 | "yiisoft/yii2": "*", 19 | "yiisoft/yii2-bootstrap": "*", 20 | "yiisoft/yii2-swiftmailer": "*" 21 | }, 22 | "require-dev": { 23 | "yiisoft/yii2-codeception": "*", 24 | "yiisoft/yii2-debug": "*", 25 | "yiisoft/yii2-gii": "*", 26 | "yiisoft/yii2-faker": "*" 27 | }, 28 | "config": { 29 | "process-timeout": 1800 30 | }, 31 | "scripts": { 32 | "post-create-project-cmd": [ 33 | "yii\\composer\\Installer::postCreateProject" 34 | ] 35 | }, 36 | "extra": { 37 | "yii\\composer\\Installer::postCreateProject": { 38 | "setPermission": [ 39 | { 40 | "runtime": "0777", 41 | "web/assets": "0777", 42 | "yii": "0755" 43 | } 44 | ], 45 | "generateCookieValidationKey": [ 46 | "config/web.php" 47 | ] 48 | }, 49 | "asset-installer-paths": { 50 | "npm-asset-library": "vendor/npm", 51 | "bower-asset-library": "vendor/bower" 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "10d8d3b92d960bec820ae06a5e92ecc8", 8 | "packages": [ 9 | { 10 | "name": "bower-asset/bootstrap", 11 | "version": "v3.3.2", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/twbs/bootstrap.git", 15 | "reference": "bcf7dd38b5ab180256e2e4fb5da0369551b3f082" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/twbs/bootstrap/zipball/bcf7dd38b5ab180256e2e4fb5da0369551b3f082", 20 | "reference": "bcf7dd38b5ab180256e2e4fb5da0369551b3f082", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "bower-asset/jquery": ">=1.9.1" 25 | }, 26 | "type": "bower-asset-library", 27 | "extra": { 28 | "bower-asset-main": [ 29 | "less/bootstrap.less", 30 | "dist/css/bootstrap.css", 31 | "dist/js/bootstrap.js", 32 | "dist/fonts/glyphicons-halflings-regular.eot", 33 | "dist/fonts/glyphicons-halflings-regular.svg", 34 | "dist/fonts/glyphicons-halflings-regular.ttf", 35 | "dist/fonts/glyphicons-halflings-regular.woff" 36 | ], 37 | "bower-asset-ignore": [ 38 | "/.*", 39 | "_config.yml", 40 | "CNAME", 41 | "composer.json", 42 | "CONTRIBUTING.md", 43 | "docs", 44 | "js/tests", 45 | "test-infra" 46 | ] 47 | }, 48 | "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.", 49 | "keywords": [ 50 | "css", 51 | "framework", 52 | "front-end", 53 | "js", 54 | "less", 55 | "mobile-first", 56 | "responsive", 57 | "web" 58 | ] 59 | }, 60 | { 61 | "name": "bower-asset/jquery", 62 | "version": "2.1.3", 63 | "source": { 64 | "type": "git", 65 | "url": "https://github.com/jquery/jquery.git", 66 | "reference": "8f2a9d9272d6ed7f32d3a484740ab342c02541e0" 67 | }, 68 | "dist": { 69 | "type": "zip", 70 | "url": "https://api.github.com/repos/jquery/jquery/zipball/8f2a9d9272d6ed7f32d3a484740ab342c02541e0", 71 | "reference": "8f2a9d9272d6ed7f32d3a484740ab342c02541e0", 72 | "shasum": "" 73 | }, 74 | "require-dev": { 75 | "bower-asset/qunit": "1.14.0", 76 | "bower-asset/requirejs": "2.1.10", 77 | "bower-asset/sinon": "1.8.1", 78 | "bower-asset/sizzle": "2.1.1-patch2" 79 | }, 80 | "type": "bower-asset-library", 81 | "extra": { 82 | "bower-asset-main": "dist/jquery.js", 83 | "bower-asset-ignore": [ 84 | "**/.*", 85 | "build", 86 | "speed", 87 | "test", 88 | "*.md", 89 | "AUTHORS.txt", 90 | "Gruntfile.js", 91 | "package.json" 92 | ] 93 | }, 94 | "license": [ 95 | "MIT" 96 | ], 97 | "keywords": [ 98 | "javascript", 99 | "jquery", 100 | "library" 101 | ] 102 | }, 103 | { 104 | "name": "bower-asset/jquery.inputmask", 105 | "version": "3.1.61", 106 | "source": { 107 | "type": "git", 108 | "url": "https://github.com/RobinHerbots/jquery.inputmask.git", 109 | "reference": "f2c086411d2557fc485c47afb3cecfa6c1de9ee2" 110 | }, 111 | "dist": { 112 | "type": "zip", 113 | "url": "https://api.github.com/repos/RobinHerbots/jquery.inputmask/zipball/f2c086411d2557fc485c47afb3cecfa6c1de9ee2", 114 | "reference": "f2c086411d2557fc485c47afb3cecfa6c1de9ee2", 115 | "shasum": "" 116 | }, 117 | "require": { 118 | "bower-asset/jquery": ">=1.7" 119 | }, 120 | "type": "bower-asset-library", 121 | "extra": { 122 | "bower-asset-main": [ 123 | "./dist/inputmask/jquery.inputmask.js", 124 | "./dist/inputmask/jquery.inputmask.extensions.js", 125 | "./dist/inputmask/jquery.inputmask.date.extensions.js", 126 | "./dist/inputmask/jquery.inputmask.numeric.extensions.js", 127 | "./dist/inputmask/jquery.inputmask.phone.extensions.js", 128 | "./dist/inputmask/jquery.inputmask.regex.extensions.js" 129 | ], 130 | "bower-asset-ignore": [ 131 | "**/.*", 132 | "qunit/", 133 | "nuget/", 134 | "tools/", 135 | "js/", 136 | "*.md", 137 | "build.properties", 138 | "build.xml", 139 | "jquery.inputmask.jquery.json" 140 | ] 141 | }, 142 | "license": [ 143 | "http://opensource.org/licenses/mit-license.php" 144 | ], 145 | "description": "jquery.inputmask is a jquery plugin which create an input mask.", 146 | "keywords": [ 147 | "form", 148 | "input", 149 | "inputmask", 150 | "jquery", 151 | "mask", 152 | "plugins" 153 | ] 154 | }, 155 | { 156 | "name": "bower-asset/punycode", 157 | "version": "v1.3.2", 158 | "source": { 159 | "type": "git", 160 | "url": "https://github.com/bestiejs/punycode.js.git", 161 | "reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3" 162 | }, 163 | "dist": { 164 | "type": "zip", 165 | "url": "https://api.github.com/repos/bestiejs/punycode.js/zipball/38c8d3131a82567bfef18da09f7f4db68c84f8a3", 166 | "reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3", 167 | "shasum": "" 168 | }, 169 | "type": "bower-asset-library", 170 | "extra": { 171 | "bower-asset-main": "punycode.js", 172 | "bower-asset-ignore": [ 173 | "coverage", 174 | "tests", 175 | ".*", 176 | "component.json", 177 | "Gruntfile.js", 178 | "node_modules", 179 | "package.json" 180 | ] 181 | } 182 | }, 183 | { 184 | "name": "bower-asset/yii2-pjax", 185 | "version": "dev-master", 186 | "source": { 187 | "type": "git", 188 | "url": "https://github.com/yiisoft/jquery-pjax.git", 189 | "reference": "b7491aec282bfd2e78faf33b18df865299b88d36" 190 | }, 191 | "dist": { 192 | "type": "zip", 193 | "url": "https://api.github.com/repos/yiisoft/jquery-pjax/zipball/b7491aec282bfd2e78faf33b18df865299b88d36", 194 | "reference": "b7491aec282bfd2e78faf33b18df865299b88d36", 195 | "shasum": "" 196 | }, 197 | "require": { 198 | "bower-asset/jquery": ">=1.8" 199 | }, 200 | "type": "bower-asset-library", 201 | "extra": { 202 | "bower-asset-main": "./jquery.pjax.js", 203 | "bower-asset-ignore": [ 204 | ".travis.yml", 205 | "Gemfile", 206 | "Gemfile.lock", 207 | "vendor/", 208 | "script/", 209 | "test/" 210 | ] 211 | }, 212 | "license": [ 213 | "MIT" 214 | ] 215 | }, 216 | { 217 | "name": "cebe/markdown", 218 | "version": "dev-master", 219 | "source": { 220 | "type": "git", 221 | "url": "https://github.com/cebe/markdown.git", 222 | "reference": "f89dc1da1fc6823f0286d6cad736a642efd0f59e" 223 | }, 224 | "dist": { 225 | "type": "zip", 226 | "url": "https://api.github.com/repos/cebe/markdown/zipball/f89dc1da1fc6823f0286d6cad736a642efd0f59e", 227 | "reference": "f89dc1da1fc6823f0286d6cad736a642efd0f59e", 228 | "shasum": "" 229 | }, 230 | "require": { 231 | "lib-pcre": "*", 232 | "php": ">=5.4.0" 233 | }, 234 | "require-dev": { 235 | "cebe/indent": "*", 236 | "facebook/xhprof": "*@dev", 237 | "phpunit/phpunit": "3.7.*" 238 | }, 239 | "bin": [ 240 | "bin/markdown" 241 | ], 242 | "type": "library", 243 | "extra": { 244 | "branch-alias": { 245 | "dev-master": "1.0.x-dev" 246 | } 247 | }, 248 | "autoload": { 249 | "psr-4": { 250 | "cebe\\markdown\\": "" 251 | } 252 | }, 253 | "notification-url": "https://packagist.org/downloads/", 254 | "license": [ 255 | "MIT" 256 | ], 257 | "authors": [ 258 | { 259 | "name": "Carsten Brandt", 260 | "email": "mail@cebe.cc", 261 | "homepage": "http://cebe.cc/", 262 | "role": "Creator" 263 | } 264 | ], 265 | "description": "A super fast, highly extensible markdown parser for PHP", 266 | "homepage": "https://github.com/cebe/markdown#readme", 267 | "keywords": [ 268 | "extensible", 269 | "fast", 270 | "gfm", 271 | "markdown", 272 | "markdown-extra" 273 | ], 274 | "time": "2014-12-18 00:45:32" 275 | }, 276 | { 277 | "name": "ezyang/htmlpurifier", 278 | "version": "v4.6.0", 279 | "source": { 280 | "type": "git", 281 | "url": "https://github.com/ezyang/htmlpurifier.git", 282 | "reference": "6f389f0f25b90d0b495308efcfa073981177f0fd" 283 | }, 284 | "dist": { 285 | "type": "zip", 286 | "url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/6f389f0f25b90d0b495308efcfa073981177f0fd", 287 | "reference": "6f389f0f25b90d0b495308efcfa073981177f0fd", 288 | "shasum": "" 289 | }, 290 | "require": { 291 | "php": ">=5.2" 292 | }, 293 | "type": "library", 294 | "autoload": { 295 | "psr-0": { 296 | "HTMLPurifier": "library/" 297 | }, 298 | "files": [ 299 | "library/HTMLPurifier.composer.php" 300 | ] 301 | }, 302 | "notification-url": "https://packagist.org/downloads/", 303 | "license": [ 304 | "LGPL" 305 | ], 306 | "authors": [ 307 | { 308 | "name": "Edward Z. Yang", 309 | "email": "admin@htmlpurifier.org", 310 | "homepage": "http://ezyang.com" 311 | } 312 | ], 313 | "description": "Standards compliant HTML filter written in PHP", 314 | "homepage": "http://htmlpurifier.org/", 315 | "keywords": [ 316 | "html" 317 | ], 318 | "time": "2013-11-30 08:25:19" 319 | }, 320 | { 321 | "name": "swiftmailer/swiftmailer", 322 | "version": "dev-master", 323 | "source": { 324 | "type": "git", 325 | "url": "https://github.com/swiftmailer/swiftmailer.git", 326 | "reference": "db95cfa68a8bc91d1c54f75c416f481c9a8bd100" 327 | }, 328 | "dist": { 329 | "type": "zip", 330 | "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/db95cfa68a8bc91d1c54f75c416f481c9a8bd100", 331 | "reference": "db95cfa68a8bc91d1c54f75c416f481c9a8bd100", 332 | "shasum": "" 333 | }, 334 | "require": { 335 | "php": ">=5.3.3" 336 | }, 337 | "require-dev": { 338 | "mockery/mockery": "~0.9.1" 339 | }, 340 | "type": "library", 341 | "extra": { 342 | "branch-alias": { 343 | "dev-master": "5.3-dev" 344 | } 345 | }, 346 | "autoload": { 347 | "files": [ 348 | "lib/swift_required.php" 349 | ] 350 | }, 351 | "notification-url": "https://packagist.org/downloads/", 352 | "license": [ 353 | "MIT" 354 | ], 355 | "authors": [ 356 | { 357 | "name": "Chris Corbyn" 358 | }, 359 | { 360 | "name": "Fabien Potencier", 361 | "email": "fabien@symfony.com" 362 | } 363 | ], 364 | "description": "Swiftmailer, free feature-rich PHP mailer", 365 | "homepage": "http://swiftmailer.org", 366 | "keywords": [ 367 | "mail", 368 | "mailer" 369 | ], 370 | "time": "2015-01-18 13:49:36" 371 | }, 372 | { 373 | "name": "yiisoft/yii2", 374 | "version": "dev-master", 375 | "source": { 376 | "type": "git", 377 | "url": "https://github.com/yiisoft/yii2-framework.git", 378 | "reference": "b95c0de6191b2c438eecad4e6cffca0fe4c7c640" 379 | }, 380 | "dist": { 381 | "type": "zip", 382 | "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/b95c0de6191b2c438eecad4e6cffca0fe4c7c640", 383 | "reference": "b95c0de6191b2c438eecad4e6cffca0fe4c7c640", 384 | "shasum": "" 385 | }, 386 | "require": { 387 | "bower-asset/jquery": "2.1.*@stable | 1.11.*@stable", 388 | "bower-asset/jquery.inputmask": "3.1.*", 389 | "bower-asset/punycode": "1.3.*", 390 | "bower-asset/yii2-pjax": ">=2.0.1", 391 | "cebe/markdown": "~1.0.0", 392 | "ext-mbstring": "*", 393 | "ext-mcrypt": "*", 394 | "ezyang/htmlpurifier": "4.6.*", 395 | "lib-pcre": "*", 396 | "php": ">=5.4.0", 397 | "yiisoft/yii2-composer": "*" 398 | }, 399 | "bin": [ 400 | "yii" 401 | ], 402 | "type": "library", 403 | "extra": { 404 | "branch-alias": { 405 | "dev-master": "2.0.x-dev" 406 | } 407 | }, 408 | "autoload": { 409 | "psr-4": { 410 | "yii\\": "" 411 | } 412 | }, 413 | "notification-url": "https://packagist.org/downloads/", 414 | "license": [ 415 | "BSD-3-Clause" 416 | ], 417 | "authors": [ 418 | { 419 | "name": "Qiang Xue", 420 | "email": "qiang.xue@gmail.com", 421 | "homepage": "http://www.yiiframework.com/", 422 | "role": "Founder and project lead" 423 | }, 424 | { 425 | "name": "Alexander Makarov", 426 | "email": "sam@rmcreative.ru", 427 | "homepage": "http://rmcreative.ru/", 428 | "role": "Core framework development" 429 | }, 430 | { 431 | "name": "Maurizio Domba", 432 | "homepage": "http://mdomba.info/", 433 | "role": "Core framework development" 434 | }, 435 | { 436 | "name": "Carsten Brandt", 437 | "email": "mail@cebe.cc", 438 | "homepage": "http://cebe.cc/", 439 | "role": "Core framework development" 440 | }, 441 | { 442 | "name": "Timur Ruziev", 443 | "email": "resurtm@gmail.com", 444 | "homepage": "http://resurtm.com/", 445 | "role": "Core framework development" 446 | }, 447 | { 448 | "name": "Paul Klimov", 449 | "email": "klimov.paul@gmail.com", 450 | "role": "Core framework development" 451 | } 452 | ], 453 | "description": "Yii PHP Framework Version 2", 454 | "homepage": "http://www.yiiframework.com/", 455 | "keywords": [ 456 | "framework", 457 | "yii2" 458 | ], 459 | "time": "2015-02-05 14:24:17" 460 | }, 461 | { 462 | "name": "yiisoft/yii2-bootstrap", 463 | "version": "dev-master", 464 | "source": { 465 | "type": "git", 466 | "url": "https://github.com/yiisoft/yii2-bootstrap.git", 467 | "reference": "d6daff0dc635c87659754b16107843501355eae3" 468 | }, 469 | "dist": { 470 | "type": "zip", 471 | "url": "https://api.github.com/repos/yiisoft/yii2-bootstrap/zipball/d6daff0dc635c87659754b16107843501355eae3", 472 | "reference": "d6daff0dc635c87659754b16107843501355eae3", 473 | "shasum": "" 474 | }, 475 | "require": { 476 | "bower-asset/bootstrap": "3.3.* | 3.2.* | 3.1.*", 477 | "yiisoft/yii2": "*" 478 | }, 479 | "type": "yii2-extension", 480 | "extra": { 481 | "branch-alias": { 482 | "dev-master": "2.0.x-dev" 483 | } 484 | }, 485 | "autoload": { 486 | "psr-4": { 487 | "yii\\bootstrap\\": "" 488 | } 489 | }, 490 | "notification-url": "https://packagist.org/downloads/", 491 | "license": [ 492 | "BSD-3-Clause" 493 | ], 494 | "authors": [ 495 | { 496 | "name": "Qiang Xue", 497 | "email": "qiang.xue@gmail.com" 498 | } 499 | ], 500 | "description": "The Twitter Bootstrap extension for the Yii framework", 501 | "keywords": [ 502 | "bootstrap", 503 | "yii2" 504 | ], 505 | "time": "2015-01-20 08:53:09" 506 | }, 507 | { 508 | "name": "yiisoft/yii2-composer", 509 | "version": "dev-master", 510 | "source": { 511 | "type": "git", 512 | "url": "https://github.com/yiisoft/yii2-composer.git", 513 | "reference": "7f21221ee85862c83f60c8f74a267e29c9dc6336" 514 | }, 515 | "dist": { 516 | "type": "zip", 517 | "url": "https://api.github.com/repos/yiisoft/yii2-composer/zipball/7f21221ee85862c83f60c8f74a267e29c9dc6336", 518 | "reference": "7f21221ee85862c83f60c8f74a267e29c9dc6336", 519 | "shasum": "" 520 | }, 521 | "require": { 522 | "composer-plugin-api": "1.0.0" 523 | }, 524 | "type": "composer-plugin", 525 | "extra": { 526 | "class": "yii\\composer\\Plugin", 527 | "branch-alias": { 528 | "dev-master": "2.0.x-dev" 529 | } 530 | }, 531 | "autoload": { 532 | "psr-4": { 533 | "yii\\composer\\": "" 534 | } 535 | }, 536 | "notification-url": "https://packagist.org/downloads/", 537 | "license": [ 538 | "BSD-3-Clause" 539 | ], 540 | "authors": [ 541 | { 542 | "name": "Qiang Xue", 543 | "email": "qiang.xue@gmail.com" 544 | } 545 | ], 546 | "description": "The composer plugin for Yii extension installer", 547 | "keywords": [ 548 | "composer", 549 | "extension installer", 550 | "yii2" 551 | ], 552 | "time": "2015-01-11 03:59:50" 553 | }, 554 | { 555 | "name": "yiisoft/yii2-swiftmailer", 556 | "version": "dev-master", 557 | "source": { 558 | "type": "git", 559 | "url": "https://github.com/yiisoft/yii2-swiftmailer.git", 560 | "reference": "e702187bb958f759c849684222ac98c4c1b08dba" 561 | }, 562 | "dist": { 563 | "type": "zip", 564 | "url": "https://api.github.com/repos/yiisoft/yii2-swiftmailer/zipball/e702187bb958f759c849684222ac98c4c1b08dba", 565 | "reference": "e702187bb958f759c849684222ac98c4c1b08dba", 566 | "shasum": "" 567 | }, 568 | "require": { 569 | "swiftmailer/swiftmailer": "*", 570 | "yiisoft/yii2": "*" 571 | }, 572 | "type": "yii2-extension", 573 | "extra": { 574 | "branch-alias": { 575 | "dev-master": "2.0.x-dev" 576 | } 577 | }, 578 | "autoload": { 579 | "psr-4": { 580 | "yii\\swiftmailer\\": "" 581 | } 582 | }, 583 | "notification-url": "https://packagist.org/downloads/", 584 | "license": [ 585 | "BSD-3-Clause" 586 | ], 587 | "authors": [ 588 | { 589 | "name": "Paul Klimov", 590 | "email": "klimov.paul@gmail.com" 591 | } 592 | ], 593 | "description": "The SwiftMailer integration for the Yii framework", 594 | "keywords": [ 595 | "email", 596 | "mail", 597 | "mailer", 598 | "swift", 599 | "swiftmailer", 600 | "yii2" 601 | ], 602 | "time": "2015-01-11 03:59:50" 603 | } 604 | ], 605 | "packages-dev": [ 606 | { 607 | "name": "bower-asset/typeahead.js", 608 | "version": "v0.10.5", 609 | "source": { 610 | "type": "git", 611 | "url": "https://github.com/twitter/typeahead.js.git", 612 | "reference": "5f198b87d1af845da502ea9df93a5e84801ce742" 613 | }, 614 | "dist": { 615 | "type": "zip", 616 | "url": "https://api.github.com/repos/twitter/typeahead.js/zipball/5f198b87d1af845da502ea9df93a5e84801ce742", 617 | "reference": "5f198b87d1af845da502ea9df93a5e84801ce742", 618 | "shasum": "" 619 | }, 620 | "require": { 621 | "bower-asset/jquery": ">=1.7" 622 | }, 623 | "require-dev": { 624 | "bower-asset/jasmine-ajax": ">=1.3.1,<1.4", 625 | "bower-asset/jasmine-jquery": ">=1.5.2,<1.6", 626 | "bower-asset/jquery": ">=1.7,<1.8" 627 | }, 628 | "type": "bower-asset-library", 629 | "extra": { 630 | "bower-asset-main": "dist/typeahead.bundle.js" 631 | } 632 | }, 633 | { 634 | "name": "fzaninotto/faker", 635 | "version": "dev-master", 636 | "source": { 637 | "type": "git", 638 | "url": "https://github.com/fzaninotto/Faker.git", 639 | "reference": "81e4eccea302300ac0c69c7ed04c94e29f580633" 640 | }, 641 | "dist": { 642 | "type": "zip", 643 | "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/81e4eccea302300ac0c69c7ed04c94e29f580633", 644 | "reference": "81e4eccea302300ac0c69c7ed04c94e29f580633", 645 | "shasum": "" 646 | }, 647 | "require": { 648 | "php": ">=5.3.3" 649 | }, 650 | "require-dev": { 651 | "phpunit/phpunit": "~4.0", 652 | "squizlabs/php_codesniffer": "~1.5" 653 | }, 654 | "suggest": { 655 | "ext-intl": "*" 656 | }, 657 | "type": "library", 658 | "extra": { 659 | "branch-alias": { 660 | "dev-master": "1.5.x-dev" 661 | } 662 | }, 663 | "autoload": { 664 | "psr-4": { 665 | "Faker\\": "src/Faker/" 666 | } 667 | }, 668 | "notification-url": "https://packagist.org/downloads/", 669 | "license": [ 670 | "MIT" 671 | ], 672 | "authors": [ 673 | { 674 | "name": "François Zaninotto" 675 | } 676 | ], 677 | "description": "Faker is a PHP library that generates fake data for you.", 678 | "keywords": [ 679 | "data", 680 | "faker", 681 | "fixtures" 682 | ], 683 | "time": "2015-01-27 08:16:46" 684 | }, 685 | { 686 | "name": "phpspec/php-diff", 687 | "version": "dev-master", 688 | "source": { 689 | "type": "git", 690 | "url": "https://github.com/phpspec/php-diff.git", 691 | "reference": "30e103d19519fe678ae64a60d77884ef3d71b28a" 692 | }, 693 | "dist": { 694 | "type": "zip", 695 | "url": "https://api.github.com/repos/phpspec/php-diff/zipball/30e103d19519fe678ae64a60d77884ef3d71b28a", 696 | "reference": "30e103d19519fe678ae64a60d77884ef3d71b28a", 697 | "shasum": "" 698 | }, 699 | "type": "library", 700 | "autoload": { 701 | "psr-0": { 702 | "Diff": "lib/" 703 | } 704 | }, 705 | "notification-url": "https://packagist.org/downloads/", 706 | "license": [ 707 | "BSD-3-Clause" 708 | ], 709 | "authors": [ 710 | { 711 | "name": "Chris Boulton", 712 | "homepage": "http://github.com/chrisboulton", 713 | "role": "Original developer" 714 | } 715 | ], 716 | "description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).", 717 | "time": "2013-11-01 13:02:21" 718 | }, 719 | { 720 | "name": "yiisoft/yii2-codeception", 721 | "version": "dev-master", 722 | "source": { 723 | "type": "git", 724 | "url": "https://github.com/yiisoft/yii2-codeception.git", 725 | "reference": "036ec922a1d080f2d7e81bece0b499717a6562d6" 726 | }, 727 | "dist": { 728 | "type": "zip", 729 | "url": "https://api.github.com/repos/yiisoft/yii2-codeception/zipball/036ec922a1d080f2d7e81bece0b499717a6562d6", 730 | "reference": "036ec922a1d080f2d7e81bece0b499717a6562d6", 731 | "shasum": "" 732 | }, 733 | "require": { 734 | "yiisoft/yii2": "*" 735 | }, 736 | "type": "yii2-extension", 737 | "extra": { 738 | "branch-alias": { 739 | "dev-master": "2.0.x-dev" 740 | } 741 | }, 742 | "autoload": { 743 | "psr-4": { 744 | "yii\\codeception\\": "" 745 | } 746 | }, 747 | "notification-url": "https://packagist.org/downloads/", 748 | "license": [ 749 | "BSD-3-Clause" 750 | ], 751 | "authors": [ 752 | { 753 | "name": "Mark Jebri", 754 | "email": "mark.github@yandex.ru" 755 | } 756 | ], 757 | "description": "The Codeception integration for the Yii framework", 758 | "keywords": [ 759 | "codeception", 760 | "yii2" 761 | ], 762 | "time": "2015-01-24 08:47:11" 763 | }, 764 | { 765 | "name": "yiisoft/yii2-debug", 766 | "version": "dev-master", 767 | "source": { 768 | "type": "git", 769 | "url": "https://github.com/yiisoft/yii2-debug.git", 770 | "reference": "fa92dcf066205df00614adf38cf3ec9188f9a9c8" 771 | }, 772 | "dist": { 773 | "type": "zip", 774 | "url": "https://api.github.com/repos/yiisoft/yii2-debug/zipball/fa92dcf066205df00614adf38cf3ec9188f9a9c8", 775 | "reference": "fa92dcf066205df00614adf38cf3ec9188f9a9c8", 776 | "shasum": "" 777 | }, 778 | "require": { 779 | "yiisoft/yii2": "*", 780 | "yiisoft/yii2-bootstrap": "*" 781 | }, 782 | "type": "yii2-extension", 783 | "extra": { 784 | "branch-alias": { 785 | "dev-master": "2.0.x-dev" 786 | } 787 | }, 788 | "autoload": { 789 | "psr-4": { 790 | "yii\\debug\\": "" 791 | } 792 | }, 793 | "notification-url": "https://packagist.org/downloads/", 794 | "license": [ 795 | "BSD-3-Clause" 796 | ], 797 | "authors": [ 798 | { 799 | "name": "Qiang Xue", 800 | "email": "qiang.xue@gmail.com" 801 | } 802 | ], 803 | "description": "The debugger extension for the Yii framework", 804 | "keywords": [ 805 | "debug", 806 | "debugger", 807 | "yii2" 808 | ], 809 | "time": "2015-01-20 18:08:25" 810 | }, 811 | { 812 | "name": "yiisoft/yii2-faker", 813 | "version": "dev-master", 814 | "source": { 815 | "type": "git", 816 | "url": "https://github.com/yiisoft/yii2-faker.git", 817 | "reference": "fc93dd57b8fcff21ecb68c76b539d78a1cd80c55" 818 | }, 819 | "dist": { 820 | "type": "zip", 821 | "url": "https://api.github.com/repos/yiisoft/yii2-faker/zipball/fc93dd57b8fcff21ecb68c76b539d78a1cd80c55", 822 | "reference": "fc93dd57b8fcff21ecb68c76b539d78a1cd80c55", 823 | "shasum": "" 824 | }, 825 | "require": { 826 | "fzaninotto/faker": "*", 827 | "yiisoft/yii2": "*" 828 | }, 829 | "type": "yii2-extension", 830 | "extra": { 831 | "branch-alias": { 832 | "dev-master": "2.0.x-dev" 833 | } 834 | }, 835 | "autoload": { 836 | "psr-4": { 837 | "yii\\faker\\": "" 838 | } 839 | }, 840 | "notification-url": "https://packagist.org/downloads/", 841 | "license": [ 842 | "BSD-3-Clause" 843 | ], 844 | "authors": [ 845 | { 846 | "name": "Mark Jebri", 847 | "email": "mark.github@yandex.ru" 848 | } 849 | ], 850 | "description": "Fixture generator. The Faker integration for the Yii framework.", 851 | "keywords": [ 852 | "Fixture", 853 | "faker", 854 | "yii2" 855 | ], 856 | "time": "2015-01-11 03:59:50" 857 | }, 858 | { 859 | "name": "yiisoft/yii2-gii", 860 | "version": "dev-master", 861 | "source": { 862 | "type": "git", 863 | "url": "https://github.com/yiisoft/yii2-gii.git", 864 | "reference": "f8b3959383b99697835e7a5887da7c5c0a5eee7d" 865 | }, 866 | "dist": { 867 | "type": "zip", 868 | "url": "https://api.github.com/repos/yiisoft/yii2-gii/zipball/f8b3959383b99697835e7a5887da7c5c0a5eee7d", 869 | "reference": "f8b3959383b99697835e7a5887da7c5c0a5eee7d", 870 | "shasum": "" 871 | }, 872 | "require": { 873 | "bower-asset/typeahead.js": "0.10.*", 874 | "phpspec/php-diff": ">=1.0.2", 875 | "yiisoft/yii2": "*", 876 | "yiisoft/yii2-bootstrap": "*" 877 | }, 878 | "type": "yii2-extension", 879 | "extra": { 880 | "branch-alias": { 881 | "dev-master": "2.0.x-dev" 882 | } 883 | }, 884 | "autoload": { 885 | "psr-4": { 886 | "yii\\gii\\": "" 887 | } 888 | }, 889 | "notification-url": "https://packagist.org/downloads/", 890 | "license": [ 891 | "BSD-3-Clause" 892 | ], 893 | "authors": [ 894 | { 895 | "name": "Qiang Xue", 896 | "email": "qiang.xue@gmail.com" 897 | } 898 | ], 899 | "description": "The Gii extension for the Yii framework", 900 | "keywords": [ 901 | "code generator", 902 | "gii", 903 | "yii2" 904 | ], 905 | "time": "2015-01-24 14:34:00" 906 | } 907 | ], 908 | "aliases": [], 909 | "minimum-stability": "dev", 910 | "stability-flags": [], 911 | "prefer-stable": false, 912 | "prefer-lowest": false, 913 | "platform": { 914 | "php": ">=5.4.0" 915 | }, 916 | "platform-dev": [] 917 | } 918 | -------------------------------------------------------------------------------- /config/console.php: -------------------------------------------------------------------------------- 1 | 'basic-console', 10 | 'basePath' => dirname(__DIR__), 11 | 'bootstrap' => ['log', 'gii'], 12 | 'controllerNamespace' => 'app\commands', 13 | 'modules' => [ 14 | 'gii' => 'yii\gii\Module', 15 | ], 16 | 'components' => [ 17 | 'cache' => [ 18 | 'class' => 'yii\caching\FileCache', 19 | ], 20 | 'log' => [ 21 | 'targets' => [ 22 | [ 23 | 'class' => 'yii\log\FileTarget', 24 | 'levels' => ['error', 'warning'], 25 | ], 26 | ], 27 | ], 28 | 'db' => $db, 29 | ], 30 | 'params' => $params, 31 | ]; 32 | -------------------------------------------------------------------------------- /config/db.php: -------------------------------------------------------------------------------- 1 | 'yii\db\Connection', 5 | 'dsn' => 'mysql:host=localhost;dbname=yii2dynamicformtut', 6 | 'username' => 'root', 7 | 'password' => '', 8 | 'charset' => 'utf8', 9 | ]; 10 | -------------------------------------------------------------------------------- /config/params.php: -------------------------------------------------------------------------------- 1 | 'admin@example.com', 5 | ]; 6 | -------------------------------------------------------------------------------- /config/web.php: -------------------------------------------------------------------------------- 1 | 'basic', 7 | 'basePath' => dirname(__DIR__), 8 | 'bootstrap' => ['log'], 9 | 'components' => [ 10 | 'request' => [ 11 | // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation 12 | 'cookieValidationKey' => 'ocRLnh9uZ54fMiYXnFvp6r803zAnWZwP', 13 | ], 14 | 'cache' => [ 15 | 'class' => 'yii\caching\FileCache', 16 | ], 17 | 'user' => [ 18 | 'identityClass' => 'app\models\User', 19 | 'enableAutoLogin' => true, 20 | ], 21 | 'errorHandler' => [ 22 | 'errorAction' => 'site/error', 23 | ], 24 | 'mailer' => [ 25 | 'class' => 'yii\swiftmailer\Mailer', 26 | // send all mails to a file by default. You have to set 27 | // 'useFileTransport' to false and configure a transport 28 | // for the mailer to send real emails. 29 | 'useFileTransport' => true, 30 | ], 31 | 'log' => [ 32 | 'traceLevel' => YII_DEBUG ? 3 : 0, 33 | 'targets' => [ 34 | [ 35 | 'class' => 'yii\log\FileTarget', 36 | 'levels' => ['error', 'warning'], 37 | ], 38 | ], 39 | ], 40 | 'db' => require(__DIR__ . '/db.php'), 41 | ], 42 | 'params' => $params, 43 | ]; 44 | 45 | if (YII_ENV_DEV) { 46 | // configuration adjustments for 'dev' environment 47 | $config['bootstrap'][] = 'debug'; 48 | $config['modules']['debug'] = 'yii\debug\Module'; 49 | 50 | $config['bootstrap'][] = 'gii'; 51 | $config['modules']['gii'] = 'yii\gii\Module'; 52 | } 53 | 54 | return $config; 55 | -------------------------------------------------------------------------------- /controllers/ReceiptController.php: -------------------------------------------------------------------------------- 1 | [ 23 | 'class' => VerbFilter::className(), 24 | 'actions' => [ 25 | 'delete' => ['post'], 26 | ], 27 | ], 28 | ]; 29 | } 30 | 31 | /** 32 | * Lists all Receipt models. 33 | * @return mixed 34 | */ 35 | public function actionIndex() 36 | { 37 | $dataProvider = new ActiveDataProvider([ 38 | 'query' => Receipt::find(), 39 | ]); 40 | 41 | return $this->render('index', [ 42 | 'dataProvider' => $dataProvider, 43 | ]); 44 | } 45 | 46 | /** 47 | * Displays a single Receipt model. 48 | * @param integer $id 49 | * @return mixed 50 | */ 51 | public function actionView($id) 52 | { 53 | return $this->render('view', [ 54 | 'model' => $this->findModel($id), 55 | ]); 56 | } 57 | 58 | /** 59 | * Creates a new Receipt model. 60 | * If creation is successful, the browser will be redirected to the 'view' page. 61 | * @return mixed 62 | */ 63 | public function actionCreate() 64 | { 65 | $model = new Receipt(); 66 | $modelDetails = []; 67 | 68 | $formDetails = Yii::$app->request->post('ReceiptDetail', []); 69 | foreach ($formDetails as $i => $formDetail) { 70 | $modelDetail = new ReceiptDetail(['scenario' => ReceiptDetail::SCENARIO_BATCH_UPDATE]); 71 | $modelDetail->setAttributes($formDetail); 72 | $modelDetails[] = $modelDetail; 73 | } 74 | 75 | //handling if the addRow button has been pressed 76 | if (Yii::$app->request->post('addRow') == 'true') { 77 | $model->load(Yii::$app->request->post()); 78 | $modelDetails[] = new ReceiptDetail(['scenario' => ReceiptDetail::SCENARIO_BATCH_UPDATE]); 79 | return $this->render('create', [ 80 | 'model' => $model, 81 | 'modelDetails' => $modelDetails 82 | ]); 83 | } 84 | 85 | if ($model->load(Yii::$app->request->post())) { 86 | if (Model::validateMultiple($modelDetails) && $model->validate()) { 87 | $model->save(); 88 | foreach($modelDetails as $modelDetail) { 89 | $modelDetail->receipt_id = $model->id; 90 | $modelDetail->save(); 91 | } 92 | return $this->redirect(['view', 'id' => $model->id]); 93 | } 94 | } 95 | 96 | return $this->render('create', [ 97 | 'model' => $model, 98 | 'modelDetails' => $modelDetails 99 | ]); 100 | } 101 | 102 | /** 103 | * Updates an existing Receipt model. 104 | * If update is successful, the browser will be redirected to the 'view' page. 105 | * @param integer $id 106 | * @return mixed 107 | */ 108 | public function actionUpdate($id) 109 | { 110 | $model = $this->findModel($id); 111 | $modelDetails = $model->receiptDetails; 112 | 113 | $formDetails = Yii::$app->request->post('ReceiptDetail', []); 114 | foreach ($formDetails as $i => $formDetail) { 115 | //loading the models if they are not new 116 | if (isset($formDetail['id']) && isset($formDetail['updateType']) && $formDetail['updateType'] != ReceiptDetail::UPDATE_TYPE_CREATE) { 117 | //making sure that it is actually a child of the main model 118 | $modelDetail = ReceiptDetail::findOne(['id' => $formDetail['id'], 'receipt_id' => $model->id]); 119 | $modelDetail->setScenario(ReceiptDetail::SCENARIO_BATCH_UPDATE); 120 | $modelDetail->setAttributes($formDetail); 121 | $modelDetails[$i] = $modelDetail; 122 | //validate here if the modelDetail loaded is valid, and if it can be updated or deleted 123 | } else { 124 | $modelDetail = new ReceiptDetail(['scenario' => ReceiptDetail::SCENARIO_BATCH_UPDATE]); 125 | $modelDetail->setAttributes($formDetail); 126 | $modelDetails[] = $modelDetail; 127 | } 128 | 129 | } 130 | 131 | //handling if the addRow button has been pressed 132 | if (Yii::$app->request->post('addRow') == 'true') { 133 | $modelDetails[] = new ReceiptDetail(['scenario' => ReceiptDetail::SCENARIO_BATCH_UPDATE]); 134 | return $this->render('update', [ 135 | 'model' => $model, 136 | 'modelDetails' => $modelDetails 137 | ]); 138 | } 139 | 140 | if ($model->load(Yii::$app->request->post())) { 141 | if (Model::validateMultiple($modelDetails) && $model->validate()) { 142 | $model->save(); 143 | foreach($modelDetails as $modelDetail) { 144 | //details that has been flagged for deletion will be deleted 145 | if ($modelDetail->updateType == ReceiptDetail::UPDATE_TYPE_DELETE) { 146 | $modelDetail->delete(); 147 | } else { 148 | //new or updated records go here 149 | $modelDetail->receipt_id = $model->id; 150 | $modelDetail->save(); 151 | } 152 | } 153 | return $this->redirect(['view', 'id' => $model->id]); 154 | } 155 | } 156 | 157 | 158 | return $this->render('update', [ 159 | 'model' => $model, 160 | 'modelDetails' => $modelDetails 161 | ]); 162 | 163 | } 164 | 165 | /** 166 | * Deletes an existing Receipt model. 167 | * If deletion is successful, the browser will be redirected to the 'index' page. 168 | * @param integer $id 169 | * @return mixed 170 | */ 171 | public function actionDelete($id) 172 | { 173 | $model = $this->findModel($id); 174 | 175 | foreach ($model->receiptDetails as $modelDetail) { 176 | $modelDetail->delete(); 177 | } 178 | 179 | $model->delete(); 180 | 181 | return $this->redirect(['index']); 182 | } 183 | 184 | /** 185 | * Finds the Receipt model based on its primary key value. 186 | * If the model is not found, a 404 HTTP exception will be thrown. 187 | * @param integer $id 188 | * @return Receipt the loaded model 189 | * @throws NotFoundHttpException if the model cannot be found 190 | */ 191 | protected function findModel($id) 192 | { 193 | if (($model = Receipt::findOne($id)) !== null) { 194 | return $model; 195 | } else { 196 | throw new NotFoundHttpException('The requested page does not exist.'); 197 | } 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /controllers/SiteController.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'class' => AccessControl::className(), 19 | 'only' => ['logout'], 20 | 'rules' => [ 21 | [ 22 | 'actions' => ['logout'], 23 | 'allow' => true, 24 | 'roles' => ['@'], 25 | ], 26 | ], 27 | ], 28 | 'verbs' => [ 29 | 'class' => VerbFilter::className(), 30 | 'actions' => [ 31 | 'logout' => ['post'], 32 | ], 33 | ], 34 | ]; 35 | } 36 | 37 | public function actions() 38 | { 39 | return [ 40 | 'error' => [ 41 | 'class' => 'yii\web\ErrorAction', 42 | ], 43 | 'captcha' => [ 44 | 'class' => 'yii\captcha\CaptchaAction', 45 | 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, 46 | ], 47 | ]; 48 | } 49 | 50 | public function actionIndex() 51 | { 52 | return $this->render('index'); 53 | } 54 | 55 | public function actionLogin() 56 | { 57 | if (!\Yii::$app->user->isGuest) { 58 | return $this->goHome(); 59 | } 60 | 61 | $model = new LoginForm(); 62 | if ($model->load(Yii::$app->request->post()) && $model->login()) { 63 | return $this->goBack(); 64 | } else { 65 | return $this->render('login', [ 66 | 'model' => $model, 67 | ]); 68 | } 69 | } 70 | 71 | public function actionLogout() 72 | { 73 | Yii::$app->user->logout(); 74 | 75 | return $this->goHome(); 76 | } 77 | 78 | public function actionContact() 79 | { 80 | $model = new ContactForm(); 81 | if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) { 82 | Yii::$app->session->setFlash('contactFormSubmitted'); 83 | 84 | return $this->refresh(); 85 | } else { 86 | return $this->render('contact', [ 87 | 'model' => $model, 88 | ]); 89 | } 90 | } 91 | 92 | public function actionAbout() 93 | { 94 | return $this->render('about'); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /mail/layouts/html.php: -------------------------------------------------------------------------------- 1 | 8 | beginPage() ?> 9 | 10 | 11 |
12 | 13 |The path to yii framework seems to be incorrect.
'; 19 | echo 'You need to install Yii framework via composer or adjust the framework path in file ' . basename(__FILE__) . '.
'; 20 | echo 'Please refer to the README on how to install Yii.
'; 21 | } 22 | 23 | require_once($frameworkPath . '/requirements/YiiRequirementChecker.php'); 24 | $requirementsChecker = new YiiRequirementChecker(); 25 | 26 | $gdMemo = $imagickMemo = 'Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required for image CAPTCHA.'; 27 | $gdOK = $imagickOK = false; 28 | 29 | if (extension_loaded('imagick')) { 30 | $imagick = new Imagick(); 31 | $imagickFormats = $imagick->queryFormats('PNG'); 32 | if (in_array('PNG', $imagickFormats)) { 33 | $imagickOK = true; 34 | } else { 35 | $imagickMemo = 'Imagick extension should be installed with PNG support in order to be used for image CAPTCHA.'; 36 | } 37 | } 38 | 39 | if (extension_loaded('gd')) { 40 | $gdInfo = gd_info(); 41 | if (!empty($gdInfo['FreeType Support'])) { 42 | $gdOK = true; 43 | } else { 44 | $gdMemo = 'GD extension should be installed with FreeType support in order to be used for image CAPTCHA.'; 45 | } 46 | } 47 | 48 | /** 49 | * Adjust requirements according to your application specifics. 50 | */ 51 | $requirements = array( 52 | // Database : 53 | array( 54 | 'name' => 'PDO extension', 55 | 'mandatory' => true, 56 | 'condition' => extension_loaded('pdo'), 57 | 'by' => 'All DB-related classes', 58 | ), 59 | array( 60 | 'name' => 'PDO SQLite extension', 61 | 'mandatory' => false, 62 | 'condition' => extension_loaded('pdo_sqlite'), 63 | 'by' => 'All DB-related classes', 64 | 'memo' => 'Required for SQLite database.', 65 | ), 66 | array( 67 | 'name' => 'PDO MySQL extension', 68 | 'mandatory' => false, 69 | 'condition' => extension_loaded('pdo_mysql'), 70 | 'by' => 'All DB-related classes', 71 | 'memo' => 'Required for MySQL database.', 72 | ), 73 | array( 74 | 'name' => 'PDO PostgreSQL extension', 75 | 'mandatory' => false, 76 | 'condition' => extension_loaded('pdo_pgsql'), 77 | 'by' => 'All DB-related classes', 78 | 'memo' => 'Required for PostgreSQL database.', 79 | ), 80 | // Cache : 81 | array( 82 | 'name' => 'Memcache extension', 83 | 'mandatory' => false, 84 | 'condition' => extension_loaded('memcache') || extension_loaded('memcached'), 85 | 'by' => 'MemCache', 86 | 'memo' => extension_loaded('memcached') ? 'To use memcached set MemCache::useMemcached totrue
.' : ''
87 | ),
88 | array(
89 | 'name' => 'APC extension',
90 | 'mandatory' => false,
91 | 'condition' => extension_loaded('apc'),
92 | 'by' => 'ApcCache',
93 | ),
94 | // CAPTCHA:
95 | array(
96 | 'name' => 'GD PHP extension with FreeType support',
97 | 'mandatory' => false,
98 | 'condition' => $gdOK,
99 | 'by' => 'Captcha',
100 | 'memo' => $gdMemo,
101 | ),
102 | array(
103 | 'name' => 'ImageMagick PHP extension with PNG support',
104 | 'mandatory' => false,
105 | 'condition' => $imagickOK,
106 | 'by' => 'Captcha',
107 | 'memo' => $imagickMemo,
108 | ),
109 | // PHP ini :
110 | 'phpExposePhp' => array(
111 | 'name' => 'Expose PHP',
112 | 'mandatory' => false,
113 | 'condition' => $requirementsChecker->checkPhpIniOff("expose_php"),
114 | 'by' => 'Security reasons',
115 | 'memo' => '"expose_php" should be disabled at php.ini',
116 | ),
117 | 'phpAllowUrlInclude' => array(
118 | 'name' => 'PHP allow url include',
119 | 'mandatory' => false,
120 | 'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"),
121 | 'by' => 'Security reasons',
122 | 'memo' => '"allow_url_include" should be disabled at php.ini',
123 | ),
124 | 'phpSmtp' => array(
125 | 'name' => 'PHP mail SMTP',
126 | 'mandatory' => false,
127 | 'condition' => strlen(ini_get('SMTP'))>0,
128 | 'by' => 'Email sending',
129 | 'memo' => 'PHP mail SMTP server required',
130 | ),
131 | );
132 | $requirementsChecker->checkYii()->check($requirements)->render();
133 |
--------------------------------------------------------------------------------
/runtime/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/tests/README.md:
--------------------------------------------------------------------------------
1 | This directory contains various tests for the basic application.
2 |
3 | Tests in `codeception` directory are developed with [Codeception PHP Testing Framework](http://codeception.com/).
4 |
5 | After creating the basic application, follow these steps to prepare for the tests:
6 |
7 | 1. Install Codeception if it's not yet installed:
8 |
9 | ```
10 | composer global require "codeception/codeception=2.0.*"
11 | composer global require "codeception/specify=*"
12 | composer global require "codeception/verify=*"
13 | ```
14 |
15 | If you've never used Composer for global packages run `composer global status`. It should output:
16 |
17 | ```
18 | Changed current directory to 17 | = Html::a('Create Receipt', ['create'], ['class' => 'btn btn-success']) ?> 18 |
19 | 20 | = GridView::widget([ 21 | 'dataProvider' => $dataProvider, 22 | 'columns' => [ 23 | ['class' => 'yii\grid\SerialColumn'], 24 | 25 | 'id', 26 | 'title', 27 | 28 | ['class' => 'yii\grid\ActionColumn'], 29 | ], 30 | ]); ?> 31 | 32 |18 | = Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> 19 | = Html::a('Delete', ['delete', 'id' => $model->id], [ 20 | 'class' => 'btn btn-danger', 21 | 'data' => [ 22 | 'confirm' => 'Are you sure you want to delete this item?', 23 | 'method' => 'post', 24 | ], 25 | ]) ?> 26 |
27 | 28 | = DetailView::widget([ 29 | 'model' => $model, 30 | 'attributes' => [ 31 | 'id', 32 | 'title', 33 | ], 34 | ]) ?> 35 |ID | 39 |Item name | 40 |
---|---|
= $receiptDetail->id ?> | 44 |= $receiptDetail->item_name ?> | 45 |
12 | This is the About page. You may modify the following file to customize its content: 13 |
14 | 15 |= __FILE__ ?>
16 |
23 | Note that if you turn on the Yii debugger, you should be able
24 | to view the mail message on the mail panel of the debugger.
25 | mailer->useFileTransport): ?>
26 | Because the application is in development mode, the email is not sent but saved as
27 | a file under = Yii::getAlias(Yii::$app->mailer->fileTransportPath) ?>
.
28 | Please configure the useFileTransport
property of the mail
29 | application component to be false to enable email sending.
30 |
31 |
36 | If you have business inquiries or other questions, please fill out the following form to contact us. Thank you. 37 |
38 | 39 |21 | The above error occurred while the Web server was processing your request. 22 |
23 |24 | Please contact us if you think this is a server error. Thank you. 25 |
26 | 27 |You have successfully created your Yii-powered application.
11 | 12 | 13 |Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et 22 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip 23 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu 24 | fugiat nulla pariatur.
25 | 26 | 27 |Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et 32 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip 33 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu 34 | fugiat nulla pariatur.
35 | 36 | 37 |Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et 42 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip 43 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu 44 | fugiat nulla pariatur.
45 | 46 | 47 |Please fill out the following fields to login:
16 | 17 | 'login-form', 19 | 'options' => ['class' => 'form-horizontal'], 20 | 'fieldConfig' => [ 21 | 'template' => "{label}\napp\models\User::$users
.
45 |