Symfony 4 translation files in directories [closed] - symfony

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to save translation files in directory, for example:
/translations/admin/messages.en.xlf
/translations/admin/validation.en.xlf
/translations/client/messages.en.xlf
/translations/client/validation.en.xlf
And how to use these translations in Controllers and Twig templates ?

Translation Resource/File Names and Locations
Symfony looks for message files (i.e. translations) in the following
default locations:
the translations/ directory (at the root of the project);
the Resources/translations/ directory inside of any bundle.
The locations are listed here with the highest priority first. That
is, you can override the translation messages of a bundle in any of
the top two directories.
The override mechanism works at a key level: only the overridden keys
need to be listed in a higher priority message file. When a key is not
found in a message file, the translator will automatically fall back
to the lower priority message files.
Source: https://symfony.com/doc/4.2/translation.html#translation-resource-file-names-and-locations
And later on the same page / chapter
You can add other directories with the paths option in the
configuration:
config/packages/translation.yaml
framework:
translator:
paths:
- '%kernel.project_dir%/translations/admin'
- '%kernel.project_dir%/translations/client'
You can use those as any other translation files, remembering the overriding mechanism quoted here above
Full reference: https://symfony.com/doc/4.2/translation.html

Related

Confuse about web hosting CPanel [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
I've read some article about deploying a website to a host. It has something like cPanel and we put all the source code into the public_html folder. And we can access those file using hostname.com/index.html will be pointed to /public_html/index.html file. My question is:
In this case, people can totally access all my source code file inside the public_html directory? It's too dangerous
By the way, some modern web design today is not access page through a file, it's instead by route. For example with Java spring MVC project: if I design a route hostname.com/users will return a page with all user, hostname.com/user/1 will return a json with user no.1. Those are all accessed by url route so how can I deploy that website in cPanel.
Please explain to me if anyone knows. Thank you.
To answer your first question, no. Not technically. Static items such as HTML/CSS/Javascript/Media Files can be accessed if they know the URL (Or you leave the indexing option enabled. Use .htaccess to disable that). PHP files are safe. The only thing people would be able to see is the OUTPUT of those. I would recommend using PHP when creating websites if possible.
You can achieve similar results to your second question be utilizing the .htaccess file and it's rewrite properties. You can also use PHP's POST/GET methods to handle events like you're suggesting.
I hope this helps!
Take a look at the file permissions settings available in cPanel on LAMP:
r = read
w = write
x = execute
You have Owner, Group, & World settings each with read, write, & execute values that can enable fine grained permissions on code, files, & folders on production web servers.

revoke and delete file after specific time asp.net mvc [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I had implemented file uploading on my website and I make a download link for the user in this way: [(Random GUID).(File Extensions)]
I want to revoke the generated download link and delete the uploaded file after 10 minutes, or revoke the download link after the first download request.
How can I achieve that?
To delete the file you either need to write a Windows Service to poll the files, or if you want to keep it really basic you can check for old files every time the page loads.
Here's the basic version:
When a user requests a download, check the creation date of all files in the target directory. If a file is over 10 minutes old - delete it. After clearing up the files it's then a simple check to see if the target file the user has requested still exists or not
You can check the creation date and delete files using the following:
string[] files = System.IO.Directory.GetFiles(#"C:\_Temp", "*.txt");
foreach (string file in files) {
DateTime creation = System.IO.File.GetCreationTime(file);
if (((TimeSpan)(DateTime.Now - creation)).TotalMinutes > 10) {
System.IO.File.Delete(file);
}
}
NOTE: Make sure you don't have any important files in the target directory. Change "*.txt" to match the file format of your uploaded files.
Next, check if the requested file still exists using:
if (File.Exists(#"C:\test.txt")) {
// process file here
}
Hope that helps :)

Designing a RESTful API for managing resources as directories and files [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I am designing a RESTful API that deals (among others) with managing directories and files.
Due to some tricky business rules (listed below) I have some troubles in finding a good structure of the resources and a good URI design...
There are many directories.
A directory has many files.
The list of files can be accessed only from their parent directory.
A specific file can be accessed "globally" (by its id only)
Files can be created, but the client should not be able to specify the parent folder (as new files are saved in a special directory and can only be moved later etc.)
Here's a possible URI design:
Get all directories:
GET /api/directories
Get properties a directory:
GET /api/directories/{directoryId}
Get files within a directory:
GET /api/directories/{directoryId}/files
Get a file:
GET /api/files/{fileId}
Delete a file:
DELETE /api/files/{fileId}
Create a file:
POST /api/files
Is this an awkward design? If yes, why?
Also, if it were to document this RESTful API, this would be a bit awkward too:
Directories resource
Resource URI:
/api/directories
Possible operations:
GET /api/directories
GET /api/directories/{directoryId}
Links to other resources:
(?) How to write this?
There is a link to the Files resource, but that is accessible only when using the second operation.
Files resource
Resource URI:
(?) ... there are two URIs... one for "get all" ("or get many") and one for the rest of the operations.
Possible operations:
GET /api/directories/{directoryId}/files
GET /api/files/{fileId}
DELETE /api/files/{fileId}
POST /api/files
Links to other resources:
Link to Directory resource - note the singular here (?)
Strictly speaking, there is no Directory resource, but there is a Directories one - should I treat these two (Directory VS Directories) separately? please see the question at the end.
Also, this link is available only in the first two operations... How to be more precise when specifying this?
Also, I've seen that some RESTful API documentations have separate entries for the collection-like resource and the instance / element-like resource (for example, see this).
Is such a granular documentation preferable? I guess one advantage would be that the "Links to other resources" (or "related resources") section of the documentation would be more precise. Or am I wrong?
Any idea is appreciated!
Thank you :)
I wouldn't say that what you have is particularly awkward. If it were me, I would support these URLs:
GET /directories
GET /directories/{directoryId} // includes a link to the files in the directory, such as /files?directoryId={directoryId}
GET /directories/{directoryId}?expand=files // includes a child collection with links to each individual file resource, and possibly other metadata as well
GET /files
GET /files?directoryId={directoryId}
POST /files
GET /files/{fileId}
DELETE /files/{fileId}
The /directories/{directoryId}/files paradigm is common, but not my favorite. If the user wants the files for a directory, they can use a query parameter on /files. If they want the files at the same time as the directory, they can use a query parameter on /directories/{directoryId}.
This is, of course, all subjective. Without knowing all the specifics, nobody's going to be able to give you a canonically correct answer.
As far as the documentation goes, there's no hard-and-fast structure. If you don't like what you have, change it to avoid the awkwardness. Also, you do have several Directory instances. Each resource that gets returned from /directories/{directoryId} is a Directory.

Symfony2: How to run the application at root directory without configure virtual host [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm using iPage as hosting, which I can't edit the virtual host , the application is now running at
http://www.xxxx.com/Symfony/web/app_dev.php
Is it possible to make some trick which allow me to run in this URL:
http://www.xxxx.com/app_dev.php
Yes. Take a look here:
Symfony 2: How to remove the "/web/" folder from the url in a shared hosting?
So, you need copy all yours "web" content into public_html (the web root directory) and put th rest: every dir (like src, vendor and so on) at the same level (just like in example I've gave you)

How to organize an ASP.NET project [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I am a PHP developer moving into an ASP.NET environment. I would like to know the best way to organize the different types of files.
Right now in my project I have the following:
3 Master Files
5 User Controls
1 Base page class
Several Web Forms
The web forms are organized into directories based on the sites structure. But do I just leave the rest of these things on the root level?
The base class can go into the app_code folder, but where do masters and user controls go?
I usually make a /MasterPages/ folder for master pages and break content down into things like /Users/ for pages in the "Users" section of the site and /Users/Controls/ for controls for those pages.
So something like this:
../ root
/Admin/
/Admin/Controls/
/JavaScript/ (or a /Includes/)
/MasterPages/
/Users/
/Users/Controls/
etc.
Structure your site like you would if you were using PHP. The directory structure doesn't affect anything* until you get into something like ASP.NET MVP.
* aside from page linking
If you put the master files in any directory. It might be possible to make problem of path. So, If you are putting your web files in any directory then put master files also there. For the user and custom control, Make a directory for them and put them in that directory and go to web.config and make a "Controls" child tag in "Pages" tag like this.
By this thing you no need to put "Register" tag on each page where you are using user controls.

Resources