# |
Jun 28th 2021, 07:54 |
dantedantas |
@conehead, thank you for your tipps. How could I load the Helper? Something like: `use Cake\ORM\Helper;` ? |
# |
Jun 28th 2021, 07:50 |
slackebot |
learn and understand :( ) |
# |
Jun 28th 2021, 07:50 |
dantedantas |
I know that I need to do the tutorial ones again and learn a lot more things in order to understand better the CakePHP environment, but the issue here is time. What I think to do is to solve by sending HTML via Ajax, and then, learn as it really should be, test and implement a new version. Or... if I find a tutorial that shows me how it should work, then I will test to see if it will not require a lot of time from my side (to |
# |
Jun 28th 2021, 07:45 |
dantedantas |
Probably it isn't the best solution. But I have not a lot of time to look for a different solution. The issue here is that I am new with CakePHP and I am also not a PHP specialist. @admad, @conehead and @kevin.pfeifer, maybe one of you could know a website or youtube tutorial that shows how I could build a solution with Ajax to load info from the DB with CakePHP? |
# |
Jun 28th 2021, 07:36 |
dantedantas |
Thank you for the help. Yes, I to return a HTML code via an Ajax Call. |
# |
Jun 28th 2021, 07:10 |
kevin.pfeifer |
as ADmad already said you really really really shouldn't just copy/move code from the view into the controller (basically break the whole MVC concept) `$this` in a controller is not the same as `$this` inside a view/template So I guess you want to return HTML via your AJAX call? |
# |
Jun 28th 2021, 07:02 |
conehead |
@dantedantas In other words: that code should still be in a view and never in the controller. Check if the request is an ajax call and render a different template if necessary. Btw: The code says that "$this->Form" is null. Cake loads the Form helper before rendering the view, which you are missing. So just in theory you would have to initiate that helper class before |
# |
Jun 28th 2021, 05:29 |
admad |
> If I copy and paste the code into a Controller Action and call it by an Ajax function in the VIEW, then it returns the error. Doh, no wonder. |
# |
Jun 28th 2021, 05:28 |
admad |
What monstrosity is this, why is there html/view code in your controller class? |
# |
Jun 28th 2021, 01:40 |
dantedantas |
Sorry, maybe I am not clear... the same code works in the VIEW. If I copy and paste the code into a Controller Action and call it by an Ajax function in the VIEW, then it returns the error. |
# |
Jun 28th 2021, 01:36 |
dantedantas |
Sorry, I pressed the "Enter button" by mistake. :( So... could someone help me to identify why I am getting this error? |
# |
Jun 28th 2021, 01:33 |
dantedantas |
Error: Call to a member function create() on null Hello Team, I am calling a Controller Action from a View (Ajax) that returns a string. The error is in this line below: `$tosal = $this->Form->create(null, ['url' => ['controller' => 'torgsal','action' => 'add']]);` My code is running in the view. I did a copy from the code at the View and inserted in the Controller the code that I copied and it works fine. |
# |
Jun 27th 2021, 18:40 |
cnizzardini |
ServerRequest accepts an array argument in the constructor |
# |
Jun 27th 2021, 18:40 |
cnizzardini |
This might be why: Unfortunately, this method of resolution has a few small limitations but is great for smaller apps. First of all, you are limited to constructor injection and secondly, all injections must be objects. |
# |
Jun 27th 2021, 18:38 |
cnizzardini |
removing `->defaultToShared()` causes the timeout elsewhere |
# |
Jun 27th 2021, 18:36 |
cnizzardini |
Yeah I was engaging Mark over twitter and he pointed me in this direction |
# |
Jun 27th 2021, 18:35 |
kevin.pfeifer |
well you can definitely create an issue where you explain what you would like to be implemented. Since this feature is not directly supported by cakephp (but the library cakephp uses for DI) I guess there needs to be more done for this to work. as well as the fact that the DI container is marked as experimental ;) |
# |
Jun 27th 2021, 18:33 |
cnizzardini |
Hmm... I wonder if I should report a bug eh? |
# |
Jun 27th 2021, 18:31 |
kevin.pfeifer |
seems like it is stuck trying to resolve the ServerRequest class because these values never change |
# |
Jun 27th 2021, 18:30 |
kevin.pfeifer |
well i can definitely confirm your error, ( i get a *`Maximum function nesting level of '256' reached`)* |
# |
Jun 27th 2021, 18:22 |
cnizzardini |
https://container.thephpleague.com/3.x/auto-wiring/ |
# |
Jun 27th 2021, 18:22 |
cnizzardini |
I'm trying to avoid needing to define the arguments using auto-wiring |
# |
Jun 27th 2021, 18:21 |
cnizzardini |
I am doing this in Plugin.php, but I don't think that should matter |
# |
Jun 27th 2021, 18:21 |
kevin.pfeifer |
well the way how I use the DI container with arguments is like that: ``` $container->add( CategoryHelper::class ); $container->add( AlfredFTP::class ) ->addArgument(CategoryHelper::class);``` |
# |
Jun 27th 2021, 18:21 |
cnizzardini |
```<b>Fatal error</b>: Maximum execution time of 30 seconds exceeded in <b>/srv/app/vendor/league/container/src/Argument/ArgumentResolverTrait.php</b> on line <b>20</b>``` |
# |
Jun 27th 2021, 18:21 |
cnizzardini |
Resulting in |
# |
Jun 27th 2021, 18:20 |
cnizzardini |
```$container ->add(GetActorService::class); $container ->defaultToShared() ->delegate((new ReflectionContainer()));``` |
# |
Jun 27th 2021, 18:20 |
cnizzardini |
So i tried something like this: |
# |
Jun 27th 2021, 18:19 |
cnizzardini |
But I'd like to not need to define the arguments |
# |
Jun 27th 2021, 18:19 |
cnizzardini |
```/** @var Container $container */ $container ->add(GetActorService::class) ->addArgument(new ActorsTable());``` |
# |
Jun 27th 2021, 18:19 |
cnizzardini |
So this works fine: |
# |
Jun 27th 2021, 18:18 |
cnizzardini |
I'm probably doing stuff wrong |
# |
Jun 27th 2021, 18:17 |
kevin.pfeifer |
I heavily use the new DI container, and got no problems. Can you explain your problem in more detail? |
# |
Jun 27th 2021, 18:16 |
cnizzardini |
Has anyone gotten auto wiring working with the new DI stuff? I am getting timeouts. |
# |
Jun 27th 2021, 15:33 |
kevin.pfeifer |
well thats something I totally overlooked when i read through the documentation :see_no_evil: ,:) |
# |
Jun 27th 2021, 15:20 |
ndm |
@alamnaryab Configure a custom finder for the related identifier's ORM Resolver, you can then contain your associations in that finder. https://stackoverflow.com/questions/63057543/cakephp-4-1-user-entity-as-authorization-identity-associated-fields/63061706#63061706 |
# |
Jun 27th 2021, 10:55 |
alamnaryab |
I think it is like below but I could not found any documentation or example ``` $result = $this->Authentication->setIdentity($userWithContainedModels); $result = $result->getResult();``` |
# |
Jun 27th 2021, 10:41 |
kevin.pfeifer |
``` $result = $this->Authentication->getResult(); if($result){ $user = $result->getData(); }``` the $user is an entity which has its own fields but does not contain any fields from other (containing) models (like roles) How to tell the authentication service that the resulting user entity should contain other models I can’t tell you right now but I am curious too :thinking_face: |
# |
Jun 26th 2021, 23:02 |
alamnaryab |
`$result = $this->Authentication->getResult();` `$result` has a protected property `_data` which has logged in user record. I am not able to find documentation how to append its protect property `_data` |
# |
Jun 26th 2021, 22:59 |
alamnaryab |
Good Morning I am using cakephp 4 Authentication plugin https://book.cakephp.org/4/en/tutorials-and-examples/cms/authentication.html on successful login I also want to get roles from database for that user. how can I do? |
# |
Jun 26th 2021, 18:52 |
cnizzardini |
nevermind, it comes from the league/container, but is not present in the cakephp container interface so phpstorm doesn't know |