Difference between #125 and #126 of
Yii v2 snippet guide

Revision #126 has been created by rackycz on Oct 4, 2019, 11:55:18 AM with the memo:

contact
« previous (#125) next (#127) »

Changes

Title unchanged

Yii v2 snippet guide

Category unchanged

Tutorials

Yii version unchanged

2.0

Tags unchanged

tutorial,beginner,yii2

Content changed

[...]
---
- Delete file web/index-test.php
- In file web/index.php comment you 2 first lines containing YII_DEBUG + YII_ENV
- Delete the text from view site/login which says "You may login with admin/admin or demo/demo."

**Saving contact inqueries into DB**
 
---
 
```SQL
 
DROP TABLE IF EXISTS `contact` ;
 
 
CREATE TABLE IF NOT EXISTS `contact` (
 
  `id` INT NOT NULL AUTO_INCREMENT,
 
  `name` VARCHAR(45) NOT NULL,
 
  `email` VARCHAR(45) NOT NULL,
 
  `subject` VARCHAR(100) NOT NULL,
 
  `body` TEXT NOT NULL,
 
  PRIMARY KEY (`id`))
 
ENGINE = InnoDB;
 
```
 
 
- Create the DB table
 
- Generate Model + CRUD using GII
 
- In Site controller replace ContactForm with Contact (in section "use" and in actionContact) and in the action change the IF condition:
 
```php
 
use app\models\Contact;
 
// ... 
 
public function actionContact() {
 
  $model = new Contact();
 
  if ($model->load(Yii::$app->request->post()) && $model->save()) {
 
  // ...
 
```
 
- Open the new contact model and add one attribute, 2 rules
 
``php
 
public $verifyCode;
 
// ...
 
['verifyCode', 'captcha'],
 
['email', 'email'],
 
// and translation for Captcha
 
'verifyCode' => Yii::t('app', 'Verification'),
 
```
 
 
- You can also delete one paragraph from view/site/contact
 
```HTML
 
<p>
 
Note that if you turn on the Yii debugger ...
 
```
 
**Tests - unit + opa** --- ... text ...
7 0
4 followers
Viewed: 274 912 times
Version: 2.0
Category: Tutorials
Written by: rackycz
Last updated by: rackycz
Created on: Sep 19, 2019
Last updated: a year ago
Update Article

Revisions

View all history