I'm quite new to PHP and have received some Symfony2 project to maintain. Now I've found out that when I update foo.html.twig, that page will not change until I perform the command console c:c -e prod. Until then the shown page will be foo.html_.twig (hence the underscore).
The problem is that I've changed a controller, let's say BarController.php, but the new added value in that controller does not work in the .twig file, I think because the BarController_.php did not get updated with the clear cache command. What did I do wrong here?
Edit:
As Nate says it's not Symfony that caches controllers, but at least I see that BarController_.php is much older than BarController.php, and it's the one with the underscore that does not have the newly added value.
Edit 2:
BarController.php and BarController_.php both reside in the same folder.
Sometimes you need to clear cache by your own. You can try
rm -rf app/cache/prod/*
and don't forget to change rights.
Apparently I was completely looking at the wrong places. It had nothing to do with caching at all.
Those underscored files appeared because of my hacky way of 'version control', which meant I copied a file I was going to edit, put '.old' after the filename so I had a backup. For some reason there was created an underscored file for these things.
The problem of not being able to read the getter's value was just a bug in my code.
Related
I upgraded Codeception to v4 (according to THIS) and then Symfony to v5 (according to THIS). Now, when I try to run tests I get an error about missing test file:
root#blabla: vendor/bin/codecept run
In GroupManager.php line 129:
GroupManager: File or directory /var/www/html/tests/unit/SomeFileCest.php does not exist
This file does NOT exist in current branch. It exists in another branch of the project, but current should not know anything about this file!
This problem happens no matter which branch I switch to. So somehow Codeception remembers, that one branch has additional test and demands that test in other branches. Looks like some sort of cache.
If I switch to the branch WITH the missing file, everything looks OK (I do get an error, but because of the old framework expected).
Error appears if I do vendor/bin/codecept run or vendor/bin/codecept run tests/functional for example (note that the missing test is a unit test).
I tried deleting /var and /vendor and running composer install/update. I also tried removing the branch completely and pulling from remote, but no joy.
Anybody has any idea why this would happen and how to fix this?
EDIT:
After some simple testing it looks like it's related to old references in tests/_support/failed (as #Naktibalda mentioned in his/her comment).
I still don't fully understand what happened, but this can be fixed by running:
vendor/bin/codecept clean
From Codeception help:
clean Recursively cleans log and generated code
I will try to investigate further to understand why this happens, but for now this is what I have.
I hope this helps someone avoid the frustrations I went through ;)
For my case we were using paracept, to run stuff in parallel. This generated group files in /tests/_data
Once I removed the group files in this folder my test suite ran normally.
Worth noting that codecept clean doesn't clear this _data folder.
Just start editing new project based on Yii 2. I am used to Yii 1.
Just for test, added string echo 'test'; to the file frontend/config/bootstrap.php.
Then I saw this string on my website. So then I removed it from frontend/config/bootstrap.php.
Unfortunately, now frontend/config/bootstrap.php contains the test string again. I tried to remove the string several times,
but it appears again and again after 5 minutes of my operation. Why?
I tried to clear Yii cache by the console, it did not help
It sounds like you would benefit from reading up on Yii 2 environments and configs.
The init command is used to initialize an environment. What it really does is copy everything from the environment directory over to the root directory where all applications are.
Essentially, files you may be editing are actually the result of Yii copying to the production location. Be sure to edit the correct set of config files and then rerun the init command.
https://www.yiiframework.com/extension/yiisoft/yii2-app-advanced/doc/guide/2.0/en/structure-environments
This used to work, but it stopped working recently. I don't think anything changed in my settings, but I have poured over them for a couple hours now just to make sure. I have checked all over google and SO too. Please pay attention to the details before claiming "this was answered over here..." Thanks. :)
Assumptions and Requirements
Assume we have two files:
<project_root>/index.php
<project_root>/folder/file.php
Assume our project root is /home/me/project.
We want to include file.php from index.php. We expect PhpStorm to be able to resolve the file path and allow us to do nifty IDE things like "Go To Declaration."
What works
require 'folder/file.php';
require '/home/me/project/folder/file.php';
$root = '/home/me/project/';
require $root.'folder/file.php';
What No Longer Works
define('ROOT_DIR', "/home/me/project/");
require ROOT_DIR.'folder/file.php';
PhpStorm does recognize the value of ROOT_DIR when I mouseover, but it highlights home and says something like: Path '"/home/me...folder/file.php' not found
Why Use a Constant Anyway?
To keep this simple, I've left out details that are not necessary to illustrate the problem. The primary thing I'd like to address is why this used to work but no longer does, and/or how can I make it work again.
Sorry, can't help. What are you really trying to do?
Here are the details I left out. If we can't solve the primary issue, perhaps we can find a good work around.
I'm working with an existing codebase. Most files require a config.php file that defines root_dir() for getting the web/project root. PhpStorm wasn't resolving those paths (understandably so), so I created a constant to takes it's place. That makes more sense anyway.
In today's battle, I discovered that you can do this:
/** #define "root_dir()" "/home/me/project/" */
// or
/** #define "ROOT_DIR" "/home/me/project/" */
If you put that anywhere in the file then PhpStorm is able to resolve all the includes/requires in that file. BUT, it only works in that file, even if you try to include/require it in another file. You'd have to do this to EVERY file to get it working everywhere. Nope. Nuh-uh. No thank you. I need to reference the absolute path to the project/web root in a way that PhpStorm will recognize across the whole project.
#LazyOne answered this in the comments. This is a bug in the latest release, and it's being tracked here: https://youtrack.jetbrains.com/issue/WI-31754
Until this gets patched I've created this work around:
Using Keyboard Maestro, I created a hotkey that will paste the #define comment at the top of the file and return the cursor to its original position. Download the macro here. Import that and edit the text.
Edit: You may actually need to edit the file in a regular text editor. One of the file paths may need to be changed to work on your system.
Note: I'm using a modified version of the Mac Eclipse keyboard layout in PHPStorm. I'm not sure that will matter.
Also, be aware that many of your "changed files" will simply have this mapping at the top of the file, and this mapping may not be correct for you teammates. I'm simply excluding those changes from my commits.
So this is the annoying kind of problem where something works perfectly on your local project, but everything breaks once deployed in production.
In this case, i can access all the pages generated by a regular codeigniter controller (situated in application/controllers). However, once i try accessing a HMVC module, i just get a codeigniter 404 error.
Situation still ok for regular controllers:
So for instance, if i have a regular controller C1 situated in application/controllers/C1.php, which contains the function page(), i can access www.mysite.com/C1/page without an issue.
Problem for accessing HMVC controllers:
However, if i want to access the controller C2 situated in application/modules/C2/controllers/C2.php, through the url www.mysite.com/C2/page, i'll get a 404 error.
And problem accessing regular controller through ajax:
A second issue appears when performing an ajax call, using a path which references a regular CI controller. The path used in the ajax call doesn't seem to be recognized, and i receive a 500 error. However, when calling the same path directly in the URL bar, the correct function seems to be executed. I had solved a similar issue before by applying the solution found in Codeigniter base_url() not working properly for ajax. However, i have not yet identified if this is the same issue.
It feels like a loader issue, but i'm no expert!
Even if it was a loader issue, why would it work on local and not on production?
Have you ever encountered something like this? Do you have an idea on how to tackle this issue?
**Edit 3: ** I removed the 2 previous edits because they are now irrelevant.
After activating the debug mode, and adding some logs, i finally found what i think to be the answer.
Long story short, my local codeigniter version runs on windows, and for some reason, when trying to reach a controller, the case is ignored. So File.php and file.php are considered the same.
My production server however runs linux, so it doesn't consider that 2 different file names refer to the same file. So i ask for file.php, and the server answer "there's no such file", because the file i actually want is File.php.
I need to turn in. I'll propose a proper answer tomorrow after running some more checks.
Thanks,
Loïc.
So the issue was not related to regular controllers versus HMVC controllers. Basically what happens is that my local dev environment is Windows, and for some reason, windows decides that the case doesn't matter when naming a file.
So file.php would be seen as the same name as File.php (notice that the first is lowercase and the second uppercase).
In my code, i was trying to get file.php (lowercase), while the actual file was named File.php and it worked, on windows.
However, in civilized operating systems File.php and file.php are considered 2 different names, and that's why suddenly things where not working in production, even though the code was the same. The controller files just could not be found.
I changed the names of my controller files (put them in lowercase) and things are working fine now.
Thanks everyone for your suggestions.
Loïc.
With HMVC routes need to be like
$route['something'] = "module/controller/function";
$route['something/(:any)'] = "module/controller/function/$1";
Make sure like that also when use controllers intead of welcome.php make sure controller filename like Welcome.php
When using routes if have not remove index.php from controller then url would be
With http://localhost/project/index.php/something
Without http://localhost/project/something
I have been developing a website using Symfony. Everything was good until earlier today I was adding some Fixtures using the DoctrineFixturesBundle and ran the "app/console" command. I received the following error:
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
Symfony\\Bundle\\AsseticBundle\\EventListener\\RequestListener
is not a valid class name for the "assetic.request_listener" service.
I tried undoing the changes I made to the fixtures to find my mistake and it didn't change. In my infinite wisdom, I decided to try updating my vendors by running "composer update" and it didn't work.
Also, when I run my site in a browser, I get the same error.
I don't know what's going on. Someone please help, any help appreciated.
For those who stop by :)
In most cases problem is with class name which has leading \ in front of class name. More info more info
Just wanted to let you all know how I fixed it. It's not the most elegant solution but it worked. I downloaded a new company of Symfony, copied over all my bundles, my whole config directory,my composer.json, and my AppKernel.php. It got rid of all my errors, even some cache issues I was getting.
For the record, this error is always related to one thing and that's the name of the class is wrong. Either you are specifying the path the class incorrectly, or you spelled the name wrong.
For instance, I got stumped on this one because I accidentally add .php to the class name.
Reformat on .xml files gave me same issue. Exactly, reformat the files in a directory instead of a single file, working with PhpStorm.
#abarisone:
Problem was in a services.xml file. PhpStorm "reformat" transform (example):
<parameter key="xxx">Petrus\xx\xx\XHRCoreExceptionListener</parameter>
to:
<parameter key="xxx">
Petrus\xx\xx\XHRCoreExceptionListener
</parameter>
Was hard to find and easy to correct, manually with help of "Local history" Phpstorm's feature.