New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Method class not found #568
Comments
The action class must be under namespace as documented. |
I am using the namespace as documnted: \App\Crud\Action\ The controller is in: src/Controllers. Is this wrong. I've done as much as the document says but the action isn't called. |
@spacebiscuit set that/or the correct namespace here instead of: 'test' => ['className' => 'App\Controller\test'] |
@bravo-kernel I have that in my code - see my gist https://gist.github.com/spacebiscuit/84cebc423c66f05c1705b9049172224a I still get missing class 'test' |
Use the proper class name with proper casing. It should be |
I've tried with: 'test' => ['className' => '\App\Controller\Test'] 'test' => ['className' => '\App\Controller\TestAction'] 'test' => ['className' => '\App\Crud\Action\TestAction'] |
How about 🎲 and try: 'test' => ['className' => '\App\Crud\Action\Test'] |
I'm not sure why I tried, but I did and the result s the same: 'test' => ['className' => '\App\Crud\Action\Test'] Is anyone able to test this to confirm the feature does actually work? |
With that last example, can you screenshot the exact filepath and gist the class you are using? |
Hi @josegonzalez as requested: File Path: The class: https://gist.github.com/spacebiscuit/a1deaa477914e68ab731dfd776772690 I am calling: offers/test.json |
Where is your TestAction class? I don't see that in your screenshot, and you gisted the controller, not the action class. What exactly are you trying to do? |
I was following this example which calls the 'drinkbeer' function in the Users controller. http://crud.readthedocs.io/en/latest/actions/custom.html#using-custom-named-controller-actions To give an overview of what I am trying to achieve. I have a Messages model, when I save to Messages via the API I want to fire an email to the User to notify them of a Message. I don't know if I should do:
OR
Email.add was what I was trying to test with the 'test' call in my example above. It seems cleaner to keep the Message.add and Email.add separate so that the two actions are distinct, or perhaps I am over-complicating matter and should keep them in the same action? Since Email.add wouldn't be related to a Model per se I was trying to add my custom function to handle the sending of emails via the API. Any suggestion and advice regarding the 'correct' approach would be welcome - thnaks! |
Okay, do you have a TestAction class? |
No i dont have that as the tutorial doesnt have the drinkbeer class but a method instead. Im confused as to whether i need a 'test' class or method. |
The tutorial mentions the following:
It assumes you created an action class at that path. You'll need to do similar, otherwise what exactly are you expecting that to execute? Note: the custom action class should be in the namespace that you provide when initializing the controller. |
I don't see how my example differs from the example in the book https://crud.readthedocs.io/en/5.2.2/actions/custom.html#using-custom-named-controller-actions. The example is using: UsersController::drinkbeer() The example has 'drinkbeer' action. I have 'test' action. The example uses the namepsace: '\App\Crud\Action\DrinkbeerAction' but it is not clear how this relates to the UsersController::drinkbeer. Can I not just call my own 'test' function in the Listings controller? I know this is painful, it is for me too, I've been trying to get this to work for 2 days now. |
You need to have a class called Since you don't have the action class, the class isn't found, thus your error. |
Example <?php
namespace App\Crud\Action;
class TestAction extends \Crud\Action\BaseAction
{
/**
* Default settings
*
* @var array
*/
protected $_defaultConfig = [
'enabled' => true,
'scope' => 'table',
'findMethod' => 'all',
'view' => null,
'viewVar' => null,
'serialize' => [],
'api' => [
'success' => [
'code' => 200
],
'error' => [
'code' => 400
]
]
];
/**
* Generic handler for all HTTP verbs
*
* @return void
*/
protected function _handle()
{
$query = $this->_table()->find($this->findMethod());
$items = $this->_controller()->paginate($query);
}
} |
I'll reopen this issue until we've figured out what the next steps are here. It's pretty clear the docs are... subpar at best here. Plus, a |
Ok so in src/Action I cresated TestAction.php. The file is as you have supplied above.
Then in my offers controller: 'test' => ['className' => '\App\Crud\Action\TestAction'] Still getting App\Crud\Action\TestAction not found though. Just to confirm, I have to create the my own class if I want a custom action? I can't use my existing Offers controller? |
Can you go on our slack channel? I feel as though you're not quite understanding what the difference between a Crud Action class and a CakePHP controller is. We can figure out what the gap is and then fill in the docs once we do. My nick there is |
I was having the same problem of class not found. I've solved it by connecting an additional resource method in the routes.php file.
'beer' is the custom action. |
I'm trying to add a custom action, following these instructions
http://crud.readthedocs.io/en/latest/actions/custom.html#using-custom-named-controller-actions
I have the following:
When I call test.json I get the following:
message: "Class 'App\Controller\TestAction' not found",
Also are the documents correct, it says to use: \App\Crud\Action\ but the top of my controller use the namespace: namespace App\Controller. I tried both but the result is the same - missing class.
What am I doing wrong?
The text was updated successfully, but these errors were encountered: