Render twig templates in Symfony 2.1 - php

I am migrating my app to Symfony 2.1 but I'm facing a big error. I've got a command which calls the templating service to render a twig template. The code +- is:
$content = $this->getContainer()->get('templating')->render('XBundle:Pdf:x.pdf.twig', array(
'variablea' => '',
'variableb' => ''
));
It was working without any problem in Symfony 2.0.X. But after migrating into Symfony 2.1, when that piece of code is called, an exception occurs:
Fatal error: Call to undefined method Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator::isFresh() in /vendor/symfony/assetic-bundle/Symfony/Bundle/AsseticBundle/Factory/Resource/FileResource.php on line 49
I've reported that in symfony/asseticbundle tracker on github like 14 days ago and nobody answers, which makes me think that I am the problem here... (https://github.com/symfony/AsseticBundle/issues/122)
What am I doing wrong?
Thanks!!

Did you clear the cache (php app/console cache:clear) and also rebuilt the bootstrap file?

Here are a few suggestions:
Check if you are using proper versions of the Symfony bundles. Compare the bundles versions in your composer.json file with versions in the default Symfony 2.1 distribution: https://github.com/symfony/symfony-standard/blob/v2.1.2/composer.json
Make sure your Symfony 2.1 installation is not still using Symfony 2.0 cache files. If you are not sure about this delete the cache folder content. In your project root directory do rm -rf app/cache/* and set up appropiate permissions as explained in the documentation: http://symfony.com/doc/current/book/installation.html#configuration-and-setup

Related

VS Code can not reach Symfony\Component and Symfony\Bundle

I am trying to create a simple symfony project.
I run this on console:
composer create-project symfony/skeleton myProjectName
php -S 127.0.0.1:8000 -t myProjectName/public
Project succesfully run at localhost:8000. However, when I begin to inspect the code, I realized VS Code editor is indicating "Undefined type" error in projectDirectory/src/Kernel.php file. Do you have any ideas why this happens and any suggestions towards solution?
I use PHP v7.4.32 and Symfony 5.4 for development. My helper extentions are PHP Intelephense v1.8.2 and PHP IntelliSense v1.0.11.
projectDirectory/src/Kernel.php
The Error
Since it runs succesfully on browser, I dubted that the classes exist somewhere but the VSCode could not solve the relative paths. Then, I tried a couple of extensions. Installation of PHP v1.22.11089 created by DEVSENSE and PHP Namespace Resolver v1.1.9 created by Mehedi Hassan has solved the problem.

template inheritance of overrided bundle

I am using symfony 3.4, but planning to update 4.0 in future.
So I reduce the bundle override step by step. ( it is prohibited in symfony 4)
For now I am planning to use template override in templtes directoly.
So I made the file here.
/templates/bundles/ApplicationSonataMediaBundle/Form/media_widgets.html
then cache clear
php app/console cache:clear
However it doesn't work.
My error messages are like this below.
Unable to find template "ApplicationSonataMediaBundle:Form:media_widgets.html.twig"
(looked into: /Users/whitebear/CodingWorks/httproot/myapp/vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views,
/Users/whitebear/CodingWorks/httproot/myapp/app/Resources/views,
/Users/whitebear/CodingWorks/httproot/myapp/templates,
/Users/whitebear/CodingWorks/httproot/myapp/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form).
Where should I check next??
your error message suggests, you have a call
$this->render('ApplicationSonataMediaBundle:Form:media_widgets.html.twig');
somewhere (plus parameters). That syntax isn't used anymore, instead use:
$this->render('#ApplicationSonataMediaBundle/Form/media_widgets.html.twig');
as shown in the Symfony templating docs (it appears this changed from symfony 3.1 to 3.2, if the docs can be trusted).

Symfony 4 on Google App Eng (flex) - 500 error

Symfony 4 app running on Google App Eng (flex).
I deployed the app, but I am getting a 500 error, and app engine is providing no additional detail.
The deploy process I did was as follows:
(Following doc https://cloud.google.com/community/tutorials/run-symfony-on-appengine-flexible)
Include an app.yaml file as follows:
runtime: php
env: flex
runtime_config:
document_root: public
front_controller_file: index.php
env_variables:
APP_ENV: "prod"
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
Update the composer line:
"post-install-cmd": [
"chmod -R ug+w $APP_DIR/var"
],
Cleared cache and warmed cache for production:
php bin/console cache:clear --env=prod --no-debug
php bin/console cache:warmup --env=prod --no-debug
Even though I haven't done the doctrine set up part, I should be able to go to xxxx.appspot.com and get the home page. Instead I get ...
xxxx.appspot.com is currently unable to handle this request. HTTP ERROR 500
This is puzzling because the app worked totally fine locally before warming the cache.
Am I deploying correctly or forgetting something? (I cant get any detail on error from App Engine).
Edit
I have checked the var/log local folder and found dev.log and prod.deprecations.log. In the latter I have this error many times ...
[2018-10-15 11:28:59] php.INFO: User Deprecated: Referencing controllers with a single colon is deprecated since Symfony 4.1, use "fos_user.security.controller::loginAction" instead. {"exception":"[object] (ErrorException(code: 0): User Deprecated: Referencing controllers with a single colon is deprecated since Symfony 4.1, use \"fos_user.security.controller::loginAction\" instead. at C:\\dev\\projects\\jw-app\\vendor\\symfony\\framework-bundle\\Routing\\DelegatingLoader.php:98)"}
Based on the new edit information you’ve just provided it seems that the issue you are encountering is more on the Symfony version you are using than GAE.
Symfony 4.1 has deprecated the bundle notation. This means that it is no longer recommended to organize your business logic using bundles. You can see some examples of this on the official Symfony web page here.
Your error message tells you to use the following:
\"fos_user.security.controller::loginAction\
For the file at path:
C:\dev\projects\jw-app\vendor\symfony\framework-bundle\Routing\DelegatingLoader.php:98)
on line 98
It seems a few people have the following referencing issues with Symfony 4.1 as well. You can view the details of their similar issue and review recommended fixes at FriendsOfSymfony Github page.
Also, I would like to mention that since you are using GAE:Flex you can view your build history and error logs for your project at the following:
Google Cloud Build ( Google Cloud Console > Open the menu > tools > Cloud Build )
This will provide you the necessary information of the build you are trying to deploy on GAE.

CakePHP 3.0 not running on other machines

I've developed a small project on a machine, using CakePHP 3.0, and I need it to run on another machine. I've tried to install it on several other machines.
If I run the composer to install the CakePHP 3.0, then I copy my stuff to overwrite it, the project works. I've tried this on two machines and had no problem so far. If I don't run the composer, and just copy the stuff to the target machine, it gives me the following error. I've tried this on 3 machines, and every machine gives me this:
Fatal error: Class 'Locale' not found in /home/u113681897/public_html/vendor/cakephp/cakephp/src/I18n/I18n.php on line 229
Fatal error: Class 'Locale' not found in /home/u113681897/public_html/vendor/cakephp/cakephp/src/I18n/I18n.php on line 229
I've copied the whole project to this server to test.
I told you this because I thought it has something to do with my problem. The point is that I have to run this on a machine that is not mine, and I can't install composer on it. The /public_html/vendor/cakephp/cakephp/src/I18n/ has files related to internationalization and localization, but my project will never be translated, so a workaround to make the project ignore those files would be enough to solve my problem.
The following code is an excerpt from the (...)/I18n/I18n.php that might be relevant:
<?php
namespace Cake\I18n;
use Aura\Intl\FormatterLocator;
use Aura\Intl\PackageLocator;
use Aura\Intl\TranslatorFactory;
use Cake\I18n\Formatter\IcuFormatter;
use Cake\I18n\Formatter\SprintfFormatter;
use Locale;
class I18n {
// lots of code here
public static function defaultLocale() {
if (static::$_defaultLocale === null) {
static::$_defaultLocale = Locale::getDefault() ?: 'en_US';
// the line above is the Line 229
}
return static::$_defaultLocale;
}
// many code here too
}
I've checked that another file also tries to access this Locale class, but I don't know if there are other files trying to access it as well. Many files from everywhere inside the project tries to access methods from I18n.php. I need it running but I can't figure out how to make it run.
Any help will be greatly appreciated.
As I just found out, prior to CakePHP 3.0, the installation must be done by composer, as stated in the 3.0 migration guide:
CakePHP should be installed with Composer
Since CakePHP can no longer easily be installed via PEAR, or in a shared
directory, those options are no longer supported. Instead you should use
Composer to install CakePHP into your application.
So it won't run on regular free web hosting services.

Symfony: Widget schema does not include the following field(s): title

I'm working in a symfony-based project. I did not do.
The page works in a simple webserver (debian+apache+php) and i move this from my home server, with Debian + Nginx + php-fpm, this works, but it throws an error that did not.
The complete error is here: http://pastebin.com/PCy0v1J6
Have you moved all your files? I guess that Brick is an object in your schema.yml, and it has a property 'title'. You should have a file BaseBrickForm.class.php in lib/form/doctrine/base, if you don't you should execute ./symfony doctrine:build --all-classes. It's common to have the autogenrated classes ignored by a versioning system, so it may be the source of your problem.
In SF_ROOT_DIR/lib/form/brickForm.class.php line 23ff you have :
$this->useFields(array('title', 'content'));
Please check the widgets defined in your BaseBrickForm.class.php file and if brickForm.class.php is extending BaseBrickForm !

Categories