Need to save data in text file. not able to get the correct text file path. Please suggest.
now, I am trying by using this code $file_url= "{{ asset('/temp_files/calender.txt') }}";
$ourFileHandle = fopen($file_url, 'w') or die("can't open file1");
but not getting the exact path.
Use templating.helper.assets, like so
$this->container->get('templating.helper.assets')->getUrl('bundles/somename/other/calendar.txt')
Where bundles/somename exists in your web/bundles folder. If you don't have anything in your web/bundles folder, then run the following command:
php app/console assets:install ./web --symlink
The other folder listed above will be one your create in the Resources/public folder of your bundle.
Related
I tried to resolve my problem all this morning but I didn't find the solution anywhere.
I have a Symfony project and I use Assetic for my css and js files.
Till today when I ran php bin/console assetic:dump --env=prod, it worked fine.
But now I have this error :
[Symfony\Component\Config\Exception\FileLocatorFileNotFoundException]
The file "C:\wamp\www\PLIE08\app/config/config_=prod.yml" does not exist.
I don't understand why it adds = in my file.
Moreover, after running this command I realized that a folder called "=prod" is created in var/cache in addition to the dev and prod folder.
I tried to update, install composer, clear the cache, look in config file if something was wrong but I'm still blocked...
Somebody can tell me why it searchs the bad file ?
Thanks
try this command bin/console assetic:dump -e prod to verify duplicated =. Otherwise remove the entire content of the cache/prod folder, doest not clear:cache, remove all manually.
I have a problem with the assets:install command in Symfony 3. As the manual states,
When executed without options, the command copies into web/ all the files found in the Resources/public/ directories of your application and bundles.
The path to my javascript file is: src/AppBundle/Resources/public/js/script.js
Now, when I run php bin/console assets:install --symlink, it puts the symlinks to web/bundles/app/js/scripts.js.
What I want is to make it create the symlink at web/bundles/AppBundle/js/scripts.js. Any hint is appreciated.
if you look inside web/bundles after running assets:install, you will see that app actually symlinks to src/AppBundle/Resources/public. so web/bundles/app/xxx should be the right convention and pointing the the right place.
web/bundles/AppBundle/xxx is the wrong convention.
I am working through symfony tutorials and the documentation, it seems to imply that in dev mode the resources are available without having to install the assets, something like:
<link rel="stylesheet" href="{{ asset("bundles/yodauser/css/login.css") }}" />
I get a 404 error though in dev mode until I actually run the assets:install command.
What am I doing wrong?
Quoting documentation:
http://symfony.com/doc/current/book/templating.html#including-stylesheets-and-javascripts-in-twig
You can also include assets located in your bundles' Resources/public
folder. You will need to run the php bin/console assets:install target
[--symlink] command, which moves (or symlinks) files into the correct
location. (target is by default "web").
<link href="{{ asset('bundles/acmedemo/css/contact.css') }}" rel="stylesheet" />
It should work, in my case sometimes it does sometimes it doeasnt.
Worst case scenario you will have to run command every time you update assets.
404 Error will be trough when the file don't exist on your server!(not found...) (W3 official doc here). The file don't exist in your target folder (or you target the wrong file ^^) ...
have you think to load your ressources in your web/ folder with this command:
# make a hard copy of the assets in web/
$ php app/console assets:install
# if possible, make absolute symlinks in web/ if not, make a hard copy
$ php app/console assets:install --symlink
# if possible, make relative symlinks in web/ if not, make a hard copy
$ php app/console assets:install --symlink --relative
This a new command on SF2.6 and you can find more samples of this command documentation here
you have all the documentation of assetics on the officoal symfony website.
And few idea for the best practise here.
Also, it's better to use the ' character in your asset() function like that :
<link rel="stylesheet" href="{{ asset('bundles/yodauser/css/login.css') }}" />
I'm trying to get the URL of my page with Twig.
So I wrote this in my index.html.twig:
{{ app.request.attributes.get("_route") }}
I'm getting this Symfony exception:
Variable "app" does not in exist in "AcmeFoo..."
I had the same problem and sometimes in addition to clearing the cache, it was necessary to rebuild the bootstrap cache. I created a little shell script (cache.sh) like this:
#!/bin/bash
cd /yoursymfonyrootfolder
php app/console cache:clear --env=prod
#path depends on symfony version
php ./vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php
Just place that file in your symfony root folder and execute it with ./cache.sh
I am trying to change the default "web" directory of symfony to something else for example public_html.
I got most of it working by following the manual here -> http://symfony.com/doc/master/cookbook/configuration/override_dir_structure.html
Very last part of that document explains how to change assetic so that assetic:dump will output to the correct directory, so that works, and the website also works.
However the document doesn't seem to explain how to change the output directory of the assets:install command.
When i run this command it still outputs to the web directory.
Does anybody know how to change this ?
assets:install requires a parameter telling where to install the assets:
app/console assets:install path
Just provide your path instead of web.
You can set a path parameter to assets:install
But I think in some case better not overriding the directory structure, preferably making a symlink to the web dir.