DARK MODE 

Posted on Friday, July 15, 2022 by

Create YouTube Clone with Yii (Part 3): Exploring Project Structure

Exploring project structure

main.php and main-local.php files (Config files)

  • There are 2 config files in backend > config
  • There are 2 config files in frontend > config
  • There are 2 config files in common > config
Configurations files in common folder is shared between backend and frontend. Meanwhile the configuration that are in backend and frontend folder respectively are individual to the backend and frontend.

Index.php file (Entry script file)

  • Location (backend): backend > web
  • Location (frontend): frontend > web
  • Everything that Yii requests start with this files
  • It uses is for:
    • Define constants
    • Register Composer autoloader
    • Include Yii files
    • Load configuration
    • Create and configure an application instance
    • Process the incoming request

Controller file

  • Location (backend): backend > controllers
  • Location (frontend): frontend > controllers
  • A class which have a couple of actions 
  • Must extends from class Controllers
  • The name of the controller is the id of the controller. Example:
    • controller name HelloController has the id of hello. In the browser, we open it as sitename.test/hello
    • controller name HelloWorldController has the if of hello-world. In the browser, we open it as sitename.test/hello-world
  • Renders view (PHP script files containing HTML and PHP code)
  • Every action function start with the keyword action. For example: actionLogin()
  • Action has an id similar to controller: Example:
    • actionIndex() has the id of index. In the browser, we open it as sitename.test/hello/index
    • actionMyIndex() has the if of my-index. In the browser, we open it as sitename.test/hello/my-index

View file

  • Location (backend): backend > views
  • Location (frontend): frontend > views
  • PHP script files containing HTML and PHP code
  • New folder must have the same name as controller. If the controller named HelloController, then the folder inside view named hello. And inside the hello folder, has the PHP file.
  • If we want to return a view using the controller, the action name should be the same as the PHP file name





No comments:

Post a Comment