Symfony 3.4 : "Could not load type ... : class does not exist" - symfony-2.8

Sorry, I'm a beginner at Symfony and I've tried to find an answer but nothing worked. I'm using Symfony3.4 which was updated from Symfony 2.8 a few months ago.
Now, I'm trying to do a rather simple thing : using a formType in a Controller, but no matter what, Symfony keeps showing the following error : Could not load type "Cha\GeneralBundle\Form\StripePaymentType": class does not exist.
Here's my StripePaymentType -really, really basic:
namespace Cha\GeneralBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
class StripePaymentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', TextType::class);
}
public function getBlockPrefix()
{
return 'cha_stripe_payment_form';
}
}
Here's my Controller action, once again, a basic thing (I didn't even write any code in there, because of this strange error) :
public function upgradeOfferPaymentAction(Offers $offers)
{
$form = $this->createForm(StripePaymentType::class);
return $this->render(
'#ChaGeneral/Offers/offer_payment.html.twig', array(
'form' => $form->createView()
));
}
I tried to use my form as a service but it did not work either :
cha.stripe.payment.form:
class: Cha\GeneralBundle\Form\StripePaymentType
tags:
- { name: cha_stripe_payment_form }
I'm probably missing something but I can't figure what...
Thank in advance for your help!

You must add this line at the top of the form class:
use Symfony\Component\Form\Extension\Core\Type\TextType;
Revert the SF version is not a solution, is just dodge the problem.

Well, finally I found what caused this problem : somebody did a composer update and we updated from Symfony 3.4.13 to Symfony 3.4.14. A simple revert did the trick, now everything is working again.
Thanks a lot for your help!

Related

Laravel 9 accessors and mutators - Simple example not working

So I am trying to get my mutators and accessors to work in Laravel 9, in my Tag model I have the following:
protected function name(): Attribute
{
return Attribute::make(
get: fn ($value) => strtolower($value),
set: fn ($value) => strtolower($value),
);
}
When displaying the name in my blade view however, the name is not being displayed in lower cases ({{ $tag->name }}), also not when saving a new model to the database.
The following does work btw:
public function getNameAttribute($value)
{
return strtolower($value);
}
Also when using public it does not work:
public function name(): Attribute
Just trying to understand what I am doing wrong here?
I am using Laravel version 9.44
I dont know if the question's content is exactly your code. I had a similiar problem, get and set not working. But it worked in other model files.
I just found the solution once again, ya, once again.
If the attribute(column name) has two words, you have to make it together, first word should be lowercase.
short_name
protected function shortName(): Attribute
{
return Attribute::make(
get: fn ($value) => strtolower($value),
set: fn ($value) => strtolower($value),
);
}
Inject the class at top of page like below
use Illuminate\Database\Eloquent\Casts\Attribute;

Lumen 8 - Using Faker in tests makes InvalidArgumentException: Unknown format "name"

I'm using Lumen default Tests only added this line to the test :
$users = \App\Models\User::factory()->count(5)->create();
But i get this error when running the test :
InvalidArgumentException: Unknown format "name"
I did't touch the UserFactory Class i include it below , whats wrong with my code?
public function definition()
{
return [
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
];
}
Should anybody else end up here looking for a similar issue in Laravel, make sure you include
parent::setUp();
in your setup method (if you have one). For example,
class ManageDocumentTest extends TestCase
{
public $user;
public function setUp():void
{
parent::setUp();
$this->user = User::factory()->create();
...
Uncommented these lines in app.php and its working now :
$app->withFacades();
$app->withEloquent();
You have to extend use Tests\TestCase instead of PHPUnit\Framework\TestCase.
At least, it helped me.
If you are using Tests\TestCase, calling parent::setUp(); and it still doesn't work, make sure not to call $faker before the actual test - ie. in a #dataProvider it won't work

On Yii framework, getting "Unable to resolve the request'

I'm trying to modify a previous developer's app and I believe I'm mimicking previous controllers but keep getting this error. After reading up, it appears my code is correct, but obviously not. Here is my code for the file .../public_html/protected/controllers/ProcessRawDataController.php
<?php
class ProcessRawData extends Controller {
public function actionIndex()
{
echo 'bla';
exit;
}
}
?>
When I go to this URL: mydomain.com/index.php?r=processRawData/index or mydomain.com/index.php?r=processRawData i get the error. I've tried changing to all lower case as well with the same result.
After posting this question, I just realized the error. The class declaration is missing the word "Controller". It should read
class ProcessRawDataController extends Controller {

Defaults in Symfony2 routing not being passed properly

I am currently trying to configure a routing option in Symfony2 so /cms will route to /cms/role/view. However, the passing of defaults doesn't seem to work properly.
/src/MyProject/CMSBundle/Resources/config/routing.yml
MyProjectCMS_specific:
pattern: /cms/{page}/{option}
defaults: { _controller: MyProjectCMSBundle:Main:index, page: role, option: view }
requirements:
_method: GET
/src/MyProject/CMSBundle/Controller/MainController.php
<?php
namespace MyProject\CMSBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class MainController extends Controller
{
public function indexAction($page, $option)
{
$response = null;
/* Switch statement that determines the page to be loaded. */
return $response;
}
}
?>
The problem is that when I try to go to `localhost/app_dev.php/cms', it gives me the following error:
Controller "MyProject\CMSBundle\Controller\MainController::indexAction()" requires that you provide a value for the "$page" argument (because there is no default value or because there is a non optional argument after this one).
500 Internal Server Error - RuntimeException
However, if I try to visit localhost/app_dev.php/cms/role or localhost/app_dev.php/cms/role/view, it gives me the correct page. I've tried adding a default route to /cms, but it still gives me the same error. How is this possible and how can I fix this?
Thanks in advance.
I don't know what is the difference between what you wrote and
public function indexAction($page = "role", $option = "view")
but maybe you could try it and tell us.

How to receive a variable in method automatically?

Is it possible to define a method like below to receive $id?
public function action_delete($id){
}
I've defined a route
Route::set('tweet', 'tweet/delete/<id>', array('id' => '\d+'))->defaults(array(
'controller'=>'tweet',
'action'=>'delete'
));
I remember a code snippet something like this few months ago...
Updated: I get the following error message
Missing argument 1 for Controller_Tweet::action_delete()
If your Kohana version < 3.2 then you can use this, however it is highly recommended that you get the id value with $this->request->param('id') -> this is the only way since 3.2 version:
public function action_delete(){
$id = $this->request->param('id');
// Rest of tour code
}
In Kohana 3.2, this doesn't work anymore. You'll have to retrieve the variable through
$id = $this->request->param('id');
See: http://kohanaframework.org/3.2/guide/api/Request#param