P
P
Pios882018-07-02 18:29:04
Yii
Pios88, 2018-07-02 18:29:04

How to create "authors" and "books" entities in Yii2?

Hello! Straight to the point: I'm a teapot. Zero knowledge of PHP. But there is an employer who, for a number of reasons, goes to a meeting and is ready to hire me and train me, provided that I do the test task by hook or by crook. I understand that it is elementary in essence, but due to the complete lack of knowledge, I can’t cope without outside help.
The essence of the task:
Implement authors and books in Yii2
Implement admin panel (CRUD for authors and books, display a list of books with the author, display a list of authors with the number of books)
Implement the output of authors and books in the public part with a simple list.
Next is the RESTfull task, but that's later.
Current state:
Installed Yii2 on the hosting
"Tightened" the MySQL database
There are 2 tables in the database: book (id, author_id, name) and author (id, name)
I already understood that I need to create models, controllers and views for both entities.
I'm confused, I can't figure out how to connect them to each other - this is the time.
And what to write. I tried to make out by analogy from different examples, but it does not work out. Three components, and until all three are ready, it is even impossible to check the intermediate results. Difficult for me. Tell me, gentlemen, I will be extremely grateful.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2018-07-03
@Pios88

If you specified links between tables in MySQL or wrote a migration with these links, and then created ActiveRecord models using gii, then the links will be put down (getBooks(), getAuthors())
And then, use gii to do CRUD.
True, without understanding PHP, you will not understand how it works.
Useful related links:
https://github.com/yiisoft/yii2/blob/master/docs/g...
https://github.com/yiisoft/yii2/blob/master/docs/g...
https ://github.com/yiisoft/yii2/blob/master/docs/g...

V
Vitaly, 2018-07-02
@Anvi-Vt

How about reading the documentation?
here, in general, you need to initially make the table a migration, and set the links, then with the help of gii the link of the tables will also be formed. Well, or use the hasMany, hasOne connection, i.e. One author can have many books, and one book can have only one author.
https://yiiframework.com.ua/ru/doc/guide/2/db-acti...
or are you waiting for someone to work for you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question