tutorials: switch to `mut f Foo`
parent
a0f8005352
commit
9315589f85
|
@ -64,7 +64,7 @@ fn main() {
|
||||||
vweb.run<App>(8080)
|
vweb.run<App>(8080)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (app mut App) index() {
|
fn (mut app App) index() {
|
||||||
app.vweb.text('Hello, world from vweb!')
|
app.vweb.text('Hello, world from vweb!')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ Vweb often uses convention over configuration and adding a new action requires
|
||||||
no routing rules either:
|
no routing rules either:
|
||||||
|
|
||||||
```v
|
```v
|
||||||
fn (app mut App) time() {
|
fn (mut app App) time() {
|
||||||
app.vweb.text(time.now().format())
|
app.vweb.text(time.now().format())
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -133,7 +133,7 @@ Let's return an HTML view instead. Create `index.html` in the same directory:
|
||||||
and update our `index()` action so that it returns the HTML view we just created:
|
and update our `index()` action so that it returns the HTML view we just created:
|
||||||
|
|
||||||
```v
|
```v
|
||||||
fn (app mut App) index() {
|
fn (mut app App) index() {
|
||||||
message := 'Hello, world from Vweb!'
|
message := 'Hello, world from Vweb!'
|
||||||
$vweb.html()
|
$vweb.html()
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ mut:
|
||||||
Modify the `init()` method we created earlier to connect to a database:
|
Modify the `init()` method we created earlier to connect to a database:
|
||||||
|
|
||||||
```v
|
```v
|
||||||
pub fn (app mut App) init() {
|
pub fn (mut app App) init() {
|
||||||
db := pg.connect(pg.Config{
|
db := pg.connect(pg.Config{
|
||||||
host: '127.0.0.1'
|
host: '127.0.0.1'
|
||||||
dbname: 'blog'
|
dbname: 'blog'
|
||||||
|
@ -336,7 +336,7 @@ Create `new.html`:
|
||||||
```
|
```
|
||||||
|
|
||||||
```v
|
```v
|
||||||
pub fn (app mut App) new_article() {
|
pub fn (mut app App) new_article() {
|
||||||
title := app.vweb.form['title']
|
title := app.vweb.form['title']
|
||||||
text := app.vweb.form['text']
|
text := app.vweb.form['text']
|
||||||
if title == '' || text == '' {
|
if title == '' || text == '' {
|
||||||
|
@ -371,7 +371,7 @@ to render everything on the client or need an API, creating JSON endpoints
|
||||||
in V is very simple:
|
in V is very simple:
|
||||||
|
|
||||||
```v
|
```v
|
||||||
pub fn (app mut App) articles() {
|
pub fn (mut app App) articles() {
|
||||||
articles := app.find_all_articles()
|
articles := app.find_all_articles()
|
||||||
app.vweb.json(json.encode(articles))
|
app.vweb.json(json.encode(articles))
|
||||||
}
|
}
|
||||||
|
@ -384,7 +384,3 @@ pub fn (app mut App) articles() {
|
||||||
To be continued...
|
To be continued...
|
||||||
|
|
||||||
For an example of a more sophisticated web app written in V, check out Vorum: https://github.com/vlang/vorum
|
For an example of a more sophisticated web app written in V, check out Vorum: https://github.com/vlang/vorum
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue