F
F
Forleyn2015-11-20 21:32:04
Yii
Forleyn, 2015-11-20 21:32:04

Development of a simple site on yii2?

I would be grateful if you tell me how to develop a bulletin board. I recently started learning about frameworks. MVC, did examples from the documentation, did a simple site in the form of a catalog on cakephp. But I was given a job on yii2 for an interview. Actually, now I would like to describe in general what I need to create, and then solve minor problems.
1) There will be 3 pages in total:
1.1 Member profile, below are displayed as comments to the profile.
1.2 Ads with summary and pagination
1.3 Page with a view of the ad itself
1.4 My ads
2) Tables that I will create:
User id, name, last_name, describe, password, img
Post id, id_user, title, describe, img
comments id, id_user , text
Actually questions:
1) In the layout I have a footer and a menu, but the menu is 2 different depending on whether the user is authorized. Should I just write 2 nav-widgets and display one of them via if, depending on whether the user is authorized or not?
2) If I connect the nav widget in the layout, and one of the menu links contains the path to the controller that will show the profile or show all the ads from this user, then I must pass the user id there, how can I actually get this user id and pass it to layout.
3) I should have different views depending on whether the user is authorized or not, types of viewing the profile, in one case just a profile and comments, in the other a form for sending a message has been added.
Check for authorization to do already in the controller and there to render resp. view?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan, 2015-11-26
@mitrm

1. Use visible

[
  'visible' => !Yii::$app->user->isGuest,
  'icon' => 'icon-home',
  'url' => ['/site/default/index'],
  'label' => 'Главная',
  'items' => [
    [
      'label' => 'Главная',
      'url' => ['/site/default/index'],
      'icon' => 'icon-bell'
    ],
  ]
],

2. If the user is authorized, the id can be accessed like this "Yii::$app->user->id", the users model "Yii::$app->user->identity"
3. either in the controller or in the view in Depending on how much the view differs, you can also use conditions in the view and include $this->render() templates

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question