How to structure this symfony web project?

I am new to Symfony and do not know how to best structure my web project. The solution should contain 3 use cases:

  • Public access to www.mydomain.com for general use
  • Only member access to member.mydomain.com
  • Admin access to admin.mydomain.com

All three virtual hosts point to the symfony / web directory

Questions:

Are these three separate applications in my Symfony project (for example, "frontend", "backend" and "admin" or "public", "member", "admin")?

  • Is this a good approach if there is some kind of duplicate code (for example, creating a list of members will be common in all three applications, but presented differently)?
  • How will I route various subdomain based applications when a user accesses * .mydomain.com? Where should this routing logic be located in Symfony?

Or is it one application with modules for each of the above use cases?

EDIT: I don't have access to httpd.conf in apache to specify the default page for virtual hosts. I can specify a directory for each subdomain using the cpanel hosting provider.

+6
php symfony1
source share
3 answers

It is difficult to say without knowing the actual responsibilities of each domain / application / independently. This is what you have to answer based on the requirements of your project ... there is no single strategy that can be recommended for each use case.

With that said, I think that you have the tasks of two applications: one will serve as an interface, and also include the functionality of "members". Resonance, I think this tug is probably a sinlge application because you want to generate links to one from the other (which is incredibly difficult to do if they are separate applications) - i.e. Everyone has access to the home page and answers frequently asked questions, but only users have access to the Downloads or something else, but still they are one and the same site.

Another application is designed for the backend and supports administrator functions. No matter how many applications you can use the same web directory, create a symlink and then specify apache accordingly:

cd htdocs ln -s SF_ROOT_DIR/web frontend ln -s SF_ROOT_DIR/web backend 

Now you can point your htdocs/frontend set to htdocs/frontend for domain.com and members.domain.com and point admin.domain.com before htdocs/backend .

Then you can change your .htaccess to look something like this:

 Options +FollowSymLinks +ExecCGI <IfModule mod_rewrite.c> RewriteEngine On # we check if the .html version is here (caching) RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f # no, so we redirect to our front web controller # if subdomain is admin.* then use backend.php application RewriteCond %{SERVER_NAME} ^admin\..*$ RewriteRule ^(.*)$ backend.php [QSA,L] # not admin so we use the frontend app RewriteRule ^(.*)$ index.php [QSA,L] </IfModule> 

That way you can use no_script_name for both applications.

Another way to do the same is to change index.php to the following:

 require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php'); if(0 === strpos($_SERVER['SERVER_NAME'], 'admin'){ $app = 'backend'; } else { $app = 'frontend'; } $configuration = ProjectConfiguration::getApplicationConfiguration($app, 'prod', false); sfContext::createInstance($configuration)->dispatch(); 

You can change the definition of the application name, but you like the idea.

Using both approaches, you can make a basic definition based on a subdomain, and you can apply this strategy regardless of the number of applications that we are talking about if you use only my recommended 2 or if you use 3.

An alternative is to make one home application. Assuming each application is just one facet of the overall application, I like to go this route. However, I would consider members, non-members, and administrators too broad a definition of modules.

If you did this, you could end up with an insane amount of action in the controllers. Instead, I would make separate modules for real problems. Also, there is no real reason to use subdomains here - it’s much easier to just use a URL segment (like / admin or / members) to use specific modules.

For example, it allows you to accept users ... Usually theres will be the admin area, so we can use the admin generator for this function and call the UserAdmin module or something like that. Then, for userland material, we could just have a User module that handles viewing and listing a common profile, editing a profile by users, and all that. Then for the actual login, we can have a UserAuth module that strictly processes things like login / logout and forgotten password requests, and what not. You can redirect any URL to any of these modules, so your routing might look something like this:

 user_login: url: /login params: {module: UserAuth, action: login} user_logout: url: /logout params: {module: UserAuth, action: logout} user_password: url: /forgot-password params: {module: UserAuth, action: recoverPassword} user_reset: url: /password/reset/:token params: {module: UserAuth, action: resetPassword} user_profile: url: /members/:username params: {module: user, action: showProfile} user_index: url: /members params: {module: User, action: index} user_default: url: /members/:action params: {module: User} admin_user: class: sfDoctrineRouteCollection options: Module: UserAdmin model: User prefix_path: /admin/user 

The final step is to make sure that you protect the appropriate modules and actions with the appropriate credential requirements in security.yml and that you also assign the credentials accordingly.

+7
source share

I think you should separate your applications publicly, from the name and administrator. Routing will be done using apache: you can use 3 document roots pointing to separate folders. The interaction of your code can be done using plugins. You can override the plugin code: for a specific application, if you need to. If access to publicly available elements has a lot in common, you might consider using the same application for both calls.

+1
source share

I would use two symfony applications. One for the public and participants, and then for the administrator functions. If the application is very difficult and difficult to maintain, simply set up protection so that only participants can view limited content.

Assuming you are in virtual or similar, subdomains are configured in Apache. If not, and you use a shared host, then I find it will be very difficult to configure symfony to work with subdomains.

+1
source share

All Articles