Hierarchy of Yii Framework - php

Please guide me about the hierarchy of Yii Framework i.e in which directory do we put html, css, javascript files and associate them with each other.

You may check the documentation (http://www.yiiframework.com/wiki/155/the-directory-structure-of-the-yii-project-site/)
To answer your question:
backend: the backend application which is mainly used site
administrators to manage the whole system.
frontend: the frontend
application which provides the main interfaces to our target end
users.
console: the console application that consists of the console
commands needed by the system.
common: the directory whose content are
shared among the above applications. As we can see, we divide the
whole system into three applications: backend, frontend and console.
If needed, we can add more applications (e.g. api, to provide Web API
service). We use common to store files that are shared among the
applications.

As you have tagged the question with Yii2 as well, here is the typical directory strucuture of Yii2 Advanced Template:
https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/structure-directories.md
Directories
The root directory contains the following subdirectories:
backend - backend web application.
common - files common to all applications.
console - console application.
environments - environment configs.
frontend - frontend web application.
Root directory contains a set of files.
.gitignore contains a list of directories ignored by git version
system. If you need something never get to your source code
repository, add it there.
composer.json - Composer config described in Configuring Composer.
init - initialization script described in Configuration and
environments.
init.bat - same for Windows.
LICENSE.md - license info. Put your project license there.
Especially when opensourcing.
README.md - basic info about installing template. Consider replacing
it with information about your project and its installation.
requirements.php - Yii requirements checker.
yii - console application bootstrap.
yii.bat - same for Windows.
There are three applications in advanced template: frontend, backend
and console. Frontend is typically what is presented to end user, the
project itself. Backend is admin panel, analytics and such
functionality. Console is typically used for cron jobs and low-level
server management. Also it's used during application deployment and
handles migrations and assets.
There's also a common directory that contains files used by more than
one application. For example, User model.
Frontend and backend are both web applications and both contain the
web directory. That's the webroot you should point your web server to.
Each application has its own namespace and alias corresponding to its
name. Same applies to the common directory.
The css, js for frontend or backend application is generally stored inside the corresponsing web/ folder.

I use follow strukture:
config
environments
runtime
vendor
my-modules
frontend
backend
other vendor
bum
uuu
www-frontend
assets
index.php
www-backend
assets
index.php
www-other-end
assets
index.php
All install/update by composer.In config directory set specific configuration. Can setup unlimeted www.

Related

How to configure Laravel project structure in IntelliJ IDEA?

Which folders I'm supposed to mark as Sources/Resources/Excluded?
My own logic based on the PHPStorm guide
Sources
The root folder
reasoning: Your source code can be in mutliple folder inside the root.
alternative: Just mark the real folder you have your code inside app, bootstrap, config, routes, (more...)
Click this button to mark the selected folder as the root for
namespaces used in your project. Based on this setting, PhpStorm
suggests you the proper folder name when you want to create a new
namespace under another parent namespace during creation or moving a
PHP class, that is, when you are actually creating or moving a PHP
class to a non-existing namespace under another parent namespace. If
no Sources folder is specified, you will have to type the proper
folder manually.
Appointing a Sources folder is not mandatory but this helps you keep
your project structure in compliance with the PSR0 and PSR4 standards.
See Configuring PHP Namespaces in a Project for details.
Tests
tests
reasoning: For obvious reasons your tests live there by default. It might be possible you use some test library for your javascript code that lives in another folder.
Click this button to mark the selected folder as a test root.
Excluded
vendor, storage, node_modules
reasoning: All (composer) libraries we use in our project live in vendor, but are not our own code. We should not search trough it by default.
In storage live caching files, files that have no significant meaning to us, we do not track them in version control (like vendor). We could just delete them and the application would still work. Same for node_modules, but this directory is for javascript packages.
Click this button to mark the selected folder as excluded so PhpStorm
ignores it during indexing, parsing, and code completion.
Resource Root
public
reasoning: Your own frontend assets should be (somewhere) under the public folder to serve to the browser. Frontend assets are (mostly?) files, javascript and css.
Click this button to enable PhpStorm to complete relative paths to
resources under the selected folder.

Symfony 3 and Angular 2 Folder Structure

I am new to both Symfony and Angular and I am trying figure out how the pieces will fit together. I want to user Symfony for my back end and web api. I want to use Angular for the front end desktop like experiences.
I am not sure how the folder structure should be. Do I put my angular javascript/typescript files in folders in the root of the Symfony project and utilize their folder structure. Or do i have two bundles in my src folder. One for the back end/website. Another for the front end? Or should the back end be serving twig templates with angular components inserted?
***** Edit *****
#Tobias Xy Correct me if I'm wrong but that would be creating bundle in the src folder and keeping the files in a resources folders in it correct?
Then i see the following at the bottom:
Frontend-Based Applications
Recently, frontend technologies like AngularJS have become pretty
popular for developing frontend web applications that talk to an API.
If you are developing an application like this, you should use the
tools that are recommended by the technology, such as Bower and
GruntJS. You should develop your frontend application separately from
your Symfony backend (even separating the repositories if you want).
So they are saying make two seperate projects and not use a bundle for the front end?
If so how do you host this? On two different sites?
Symfony is a backend framework, so there is no point in adding a bundle containing only frontend files (css, javascript, etc).
See also Web Assets (Symfony Best Practices)
They say there:
Store your assets in the web/ directory.
Update 23.03.2016
Cerad wrote in the comments: "client-side angularjs and reactjs apps have their own build system just like Symfony does".
This is actually a different topic, but the article I linked to above also says something about that:
Recently, frontend technologies like AngularJS have become pretty popular for developing frontend web applications that talk to an API.
If you are developing an application like this, you should use the tools that are recommended by the technology, such as Bower and GruntJS. You should develop your frontend application separately from your Symfony backend (even separating the repositories if you want).
For Angular 2 there might be differences in the front end build system, but the structure should be similar to the one I use for Angular 1.x.
The folder structure I use to place my front end assets in something we could describe as a three level process. Let's just enumerate the three levels here:
Level 1 - The src/AppBundle/Resources/Private folder
Inside this folder, I place any front end assets that need any kind of processing, like transpile, autoprefix, uglify, etc. This will be the case for most JS, SCSS, LESS or HTML files of your choice. You can define the folder structure you prefer.
Level 2 - The src/AppBundle/Resources/Public folder
This will be the folder that'll contain all assets after processing AND any other asset that didn't need processing, usually images, fonts, etc. This will be the folder structure that will literally be copied over to the web/bundles/app folder in Level 3.
Note: This level is indeed redundant and can be skipped with caution. In my case, I kept it to avoid 'accidents' with the way Symfony wants to install assets by default, which will replace your web/bundles/app folder with the contents of this one. This will be the case if you use any other bundle that installs assets this way, like FOSJsRoutingBundle for example.
Level 3 - The web/bundles/app folder
This is the final public destination of your assets, and the path where you'll reference them in your code. It is just a copy of the src/AppBundle/Resources/Public folder from level 2.
Build system
You will need a front end build system to transpile your files and copy them to the respective folders in level 2 and 3. In my case for Angular 1.x I used Gulp with Node. This means you'll have gulpfile.js file, package.json file and node_modules folder in your project. I didn't care, it worked fine. Just remember to not add node_modules folder to your repo.
In production
Unless you really need to rebuild in production for some reason, you can skip level 1, level 2 and gulp related folders and files like node_modules, gulpfile.js, etc.
You could create the client side as the root document and the server side as an alias location, but careful to not overwrite the alias.
Or you could change the host.
Example 1:
[client] www.example.com/<client_root_dir>
[server] www.example.com/api/<server_root_dir>
or Example 2:
[client] www.example.com/<client_root_dir>
[server] api.example.com/<server_root_dir>

Using GitHub for an existing website to track my own and vendor code changes

I'm going to implement version control for a project via GitHub. It's a website using mostly PHP and JavaScript. And we're switching from one script to another. I'm using cPanel / ftp to access the files. I would prefer not to mess around with apache config files.
/home/website/ - home directory
/home/website/public_html/ - document root for website.com - has existing php script files which will be overwritten once the beta site is tested to be working properly
/home/website/public_html/beta.website.com/ - document root for beta.website.com - has existing php script files which have been minimally modified from the original vendor source. ie header / footer / config files.
/home/website/public_html/orig.website.com/ - a possible directory where I could update the original vendor files?
/home/website/public_html/addon-website.com/ - document root for another addon domain - completely separate website has nothing to do with the project
This script is to be used on many different websites. The difference would be in:
config files
template files
website specific changes
I have the original vendor source files on my local computer but no local web server. I need help in initial setup. How should I set things up so I can track all of the following:
track changes to the original vendor files done via patches and updates
track changes to 1 or many versions of the original script installed on different websites
track changes to a beta which has my own modifications to the vendor files
track website specific changes
push changes from vendor files to where I do my own modifications
push changes from my modifications to all different websites / website specific
I had a look at how do I maintain divergent code on github but I need more specific instructions than what is provided there. Should I even be trying to do this all in one repo with many branches / forks / whatever?
It would be beneficial to have an integration branch and each party to work on features that are merged there. This is the workflow that I developed with my colleagues and has worked out very well:
http://dymitruk.com/blog/2012/02/05/branch-per-feature/
For an introduction of Git itself, this is a very good resource:
http://git-scm.com/docs

Finding a good structure for multiple apps in symfony2

This is the situation i am currently having issues with:
I have 1 webserver, this webserver must run 2 different websites, those websites are all written in symfony2 and share the same Bundle that i wrote.
Currently this bundle is placed in the src/ folder and loaded in the AppKernel.
Right now i am using the apps approach where i have 2 seperate app folders created in 1 folder called apps ( http://jolicode.com/blog/multiple-applications-with-symfony2 )
However right now my situation changed, i have this 1 webserver with 2 different websites but i also have a second webserver which must also be able to have multiple apps.
Both servers should not share the same configuration files which is having me a lot of difficulties with deploying.
I also want to prevent that i have to deploy unused bundles to a server.
I hope i explained everything as clear as possible, it is not easy to make a description.
As I read, the app folder contains all config or not files related to the app ( doctrine, Kernel, cache, logs, etc). Routing, Services or other files related to how works an specific bundle should be within that bundle in my opinion.
I think there is not a standard or good way to do this because symfony right know has the workflow one app - one project. Any structure which separates bundle config and app con
fig is valid if don't mix both kinds

How to change Symfony2 default structure?

May I change the default Symfony2 structure to fit my needs?
I like the follow structure, but don't know how to get it to working..
core/ <- Symfony2 core files
app/ <- All applications
app/Acme/ <- Application for Acme enterprise (with all bundles..)
app/clientone.com/ <- Application for Client One enterprise (with all bundles..)
Inside symfony2 distribution there are 4 main directories:
app (there are customisations to your app)
vendors (symfony and other libraries)
src (your source code which may or may not to be application specific,
there could be bundle ClientoneBundle which is specific to only this application,
but also could be a bundle reused among your applications,- such as UserBundle)
web (http document root)
So if you have several applications you could keep vendors separately. And each of your application may contain three directories like:
- apps/acme/app
- apps/acme/src
- apps/acme/web
- apps/clientone/app
- apps/clientone/src
- apps/clientone/web
- some/where/else/in/filesystem/vendor
To implement such setup is very easy,- all you have to do is edit your autoload.php (which resides in app dir), just replace everywhere __DIR__.'/../vendor to __DIR__.'/../vendor,
in other words, tell symfony2 that you moved vendors somewhere else.
(I just renamed app directory in your setup to apps - to be not confused with app directory, inside each of your application)

Categories