Get filenames of assetic files - php

I'm building a web app using Symfony2 with Assetic. I would like to make a manifest file , but I have to manually add the file names to the list.
I can use PHP to get all static files (in [app/Bundle]/Resources/public), so I can generate of list of those files easily. But the other files (stylesheets, javascripts and images) are being generated by Assetic.
Is there a way to get a list of those generated files, so I can add them to a manifest-file?

All files are registered in router
php app/console debug:router
You can see what the command is doing, by viewing the source: Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php. You can extract what you need.

Related

Laravel 8 – create route alias for image folder inside public directory

I’m in the middle of the process of replicating a framework that I developed in node / react to laravel. Right now, I’m adjusting the main architecture and currently working on a blade master page.
My original idea (Laravel 8 – use blade asset to display image, but loading from resources subfolder) didn’t work, so I’m trying a new approach to set up how I want my asset files to be served.
The assets in question is basically images for layout purposes. I organized the directory like so:
public/app_files_layout
Inside it, I have a bunch of image files that I want to access. The thing is that I don’t want to access like http://localhost:8000/app_files_layout/image-name.jpg. My intention is to access like: http://localhost:8000/images/image-name.jpg, but I want to maintain the directory names I created intact, so it can have a high fidelity architectural organization similar to my framework that I built in other languages.
I figured that I would set up a simple routing logic for it in Laravel web.php file. I followed the suggestion from this stackoverflow question:
https://stackoverflow.com/a/38736973/2510785
However, when I try to access via browser through the following address http://localhost:8000/files-layout-test/image-name.jpg, returned me an error like so:
The requested resource /files-layout-test/image-name.jpg was not found on this server.
I stripped the code just to try to find out what could be wrong, and this is what I did to debug it:
Route::get('/files-layout-test/{filename}', function($filename){
echo 'debug';
});
The strange behavior is that, when I try to access without the file extension (ex: http://localhost:8000/files-layout-test/image-name), it goes through, but I need the file extension to be there.
Any ideas on how I could get this done?
Note: I’m new to Laravel, so the answer may be simple.
Basically for simple stuff like creating a symlink for public/images and public/app_files_layout you can use the built-in storage:link command.
In your config/filesystems.php file, you can define the symlinks you want to create
'links' => [
public_path('storage') => storage_path('app/public'),
public_path('images') => public_path('app_files_layout'),
],
Then you can run php artisan storage:link and it will create all the symlinks defined the links array in config/filesystems.php. No need to create any custom Artisan command. You can read more at Laravel Docs
With the above symlink created you can use the asset() helper to generate the urls for assets which are actually in public/app_files_layout using asset('images/filename.ext').
You can also access public/app_files_layout/image-name.ext at http://localhost:8000/images/image-name.ext once the symlink is created.
However if you want to add some other logic or say you want to get user input for creating symlinks then you can define your own custom Artisan command using the storage:link command as starting point

Translate text in config folder cakephp 3

I'm trying to internationalize a CakePHP 3 application using cake i18n extract. All the texts coming from src folder are translated fine, but I have some text that I put inside config/bootstrap.php but those don't get translated even though I placed them inside the double underscore function __('My text') and I also generated the translation files in src/Locale folder (the same way I did for the other texts that work.
Any idea why my texts in config/bootstrap.php won't get translated?
Thanks in advance for any help
They do not show up because by default the extract task only looks in the src folder. When running the task it will ask you from what paths to extract, and it should only list the src folder by default.
You can either add your custom paths interactively in the shell when it asks you for the folders that should be looked up, or you can use the paths option to define them in beforehand, like:
bin/cake i18n extract --paths /var/www/app/config,/var/www/app/src
When doing so may also want to use the output option to specify the output path, as the task will use the first path as the root for output, ie with the above paths it would put the files in config/Locale instead of src/Locale. Alternatively you can switch the paths, but then the messages from the config folder files would appear at the bottom of the .pot file.
See also
Cookbook > Console Tools, Shells & Tasks > I18N Shell > Generating POT Files > Extracting from multiple folders at once
It depends on where you set the application locale with I18n::setLocale(). Your application using App.defaultLocale setting to determinate wich language sould be shown.
If you change your language in your controller, your configuration files already loaded so this will not effect on these files just on those files what will be loaded after your setLocale.
Try to change your language before translatable files loaded, or load translate configuration files in controller after changeing the appLocale.

Symfony 2.8 - Access (local) JSON from view?

I have a symfony2 app with a couple of bundles and assetic which handles my css and js.
I would like to also deploy a dataset which the view will need to draw a map - let's call it map.json.
Where should I put this file so I can access it with relative ease from a view (twig template) or other javascript file?
EDIT: In one of the controllers (written a couple years ago...) I retrieved a JSON document as follows:
$myFile = $this->get('kernel')->getRootDir() . '/../web/common/path/to/file.json';
$parameters['myFile'] = file_get_contents($myFile);
And then returned $parameters with the view. It works, but seems a bit strange... and it doesn't help me if I need to access the file from an external javascript file (eg. myJs.js).
I also don't particularly like having to hardcode asset paths, especially if I also have to do it to access it via external javascript.
The location of your json-file must be owned by www-data user and not be blocked by .htaccess so you either put it into the web folder, or put it in one of your bundles Resources/public folders which are simlinked to your webfolder.

What's the proper way to work with assets in Yii?

I notice that Yii creates strange set of directories (names like 8523d23 or 10s89b92) in assets directory, and this even happens at runtime. For example, one of my tables got more than 10 records, pagination kicked-in and I got a new files in assets subdirectory named pager.css.
When I move my site from testing to production, should I copy all those, or just create an empty "assets" directory, and it will be filled at runtime?
If I want to add, for example, some new jQuery plugin, how should I proceed?
For example, I wish to add jquery.charcounter.js, do I copy it to assets or to yii/framework/web/js/source? If I do the latter, how do I get this .js file included in HTML page output?
assets should be a writable directory. Yii takes care of assets.
By calling Yii::app()->assetManager->publish() some stylesheets, images, scripts, or even entire directories can be put into a web-visible folder.
pager.css and other non-familiar files are produced by widgets (CLinkPager for example) and other components (such as CClientScript publishes jQuery whenever you need that).
During deployment, this folder should be empty, but it doesn't really matter.
Adding plugins should never be done through framework folders. You can place them either in components dir and publish it runtime if necessary, or into any other convenient visible directory (like as images or css).
Update
To embed jquery.charcounter.js, put it in components directory, then call
Yii::app()->clientScript->registerScriptFile(
Yii::app()->assetManager->publish(
Yii::getPathOfAlias('application.components').'/jquery.charcounter.js'
),
CClientScript::POS_END
);
Regarding weird folder names, I firmly believe they are unique hashes (or part of), so they can be differentiated if application uses several extensions.
This would resolve the query as this provides detailed explanation for the assets folder:
http://www.yiiframework.com/wiki/148/understanding-assets/

serving images from a filespool using zend framework

I have a quick question about how to serve data from a repository in a application that I am writing using the Zend Framework.
My current structure is:
/application
/filespool
/library
/public
In the filespool are a number of user identifiable folders that contain user content that is uploaded via forms, mainly jpg/png and pdf. This causes issues when trying to display an image back to the user as the path in my db to reference the file is:
../filespool/0/0/1/image.jpg
which I can't display in the view script as it can't reference the image.
What would be the best way of adding the image to the view script when trying to display it back to the user? I thought about adding the filespool folder to under public but would rather leave it where it is, as that move would require a lot of work to refactor the changes.
Thanks in advance...
i guess you could try 2 diferent things ( actually just one )...
use htacces to make a virtual directory for the file pool using rewrite ( not working )
make a php file in the public directorry that takes a parameter with the path and serves the files
EDIT
Spoke to soon ... you cant use htaccess ... and that is because its outside your document root so the server cant serve files from there.

Categories