# |
May 26th 2021, 10:01 |
slackebot |
=> '<div class="form-group"><textarea class="form-control" name="{{name}}" {{attrs}}>{{value}}</textarea></div>',` `'button' => '<div class="form-group"><div><button class="btn btn-primary" {{attrs}} type="submit">{{text}}</button></div></div>',` `'inputContainerError' => '<div class="form-group has-error" {{required}}>{{content}}</div>{{error}}',` `];` |
# |
May 26th 2021, 10:01 |
slackebot |
=> '<select class="form-control" {{attrs}} name={{name}}>{{content}}<select>',` `'selectMultiple' => '<div class="form-group"><select class="form-control" multiple="multiple" {{attrs}} name={{name}}[]>{{content}}</select></div>',` `'error' => '<p class="text-danger">{{content}}</p>',` `'textarea' |
# |
May 26th 2021, 10:01 |
slackebot |
`'help' => '<small{{attrs}}>{{content}}</small>',` `'inputContainer' => '<div class="form-group">{{content}}</div>',` `'input' => '<input class="form-control" type="{{type}}" name="{{name}}" {{attrs}} />',` `'label' => '<label {{attrs}} class="control-label">{{text}}</label>',` `'select' |
# |
May 26th 2021, 10:01 |
tomrwaller |
`<?php` `return [` `'checkboxFormGroup' => '<div class="form-check"><div class="checkbox">{{label}}</div></div>',` `'checkbox' => '<input type="checkbox" class="form-check-input" name="{{name}}" value="{{value}}" {{attrs}}>',` `'checkboxWrapper' => '<div class="form-check">{{label}} {{input}}</div>',` |
# |
May 26th 2021, 10:01 |
tomrwaller |
All I'm trying to achieve is presenting a help text underneath my form controls. I think the helper I am using is causing the examples I've tried not to work. |
# |
May 26th 2021, 09:49 |
dereuromark |
Adminlte etc are the most famous |
# |
May 26th 2021, 09:48 |
dereuromark |
What's the problem? There are tons of open source ones out there if u google :) |
# |
May 26th 2021, 09:33 |
tomrwaller |
I did :) |
# |
May 26th 2021, 09:02 |
dereuromark |
Did u check the awesome list? ;) |
# |
May 26th 2021, 08:49 |
tomrwaller |
Bonus points if it's Bootstrap 5 :) But at this point I'd take anything! |
# |
May 26th 2021, 08:48 |
tomrwaller |
Hey everyone - I don't suppose anyone has a Bootstrap-enabled FormHelper template they wouldn't mind sharing with me at all? I've been using one over the years that I cobbled together through bits and pieces online but I'm noticing it doesn't provide me any scope to add input help-block text on my forms and I can't for the life of me figure it out. |
# |
May 25th 2021, 23:23 |
ljolley |
Yea this gets the job done and how I've done it in the past. |
# |
May 25th 2021, 23:21 |
ndm |
Depends on what exactly you mean by "_better_", that's very likely coupled to your specific application logic. |
# |
May 25th 2021, 23:17 |
ljolley |
(I appreciate the help btw - I've been banging my head against this for too long today) |
# |
May 25th 2021, 23:17 |
ljolley |
can you see a better way of handling this? Basically I have a set of logic that I need to run on every action with simple comparison checks - and if they fail, I redirect to where the user should be. |
# |
May 25th 2021, 23:15 |
ndm |
Basically, yes. |
# |
May 25th 2021, 23:15 |
ljolley |
got it. I modified my controller `beforeFilter` to have this: `return parent::beforeFilter($event);` and it appears to be doing what I need it to do. Is that what you meant by "overwritten method makes no use of it"? |
# |
May 25th 2021, 23:12 |
ndm |
Alternatively, if applicable, you could also set the return value of `$this->redirect()` as the event result. |
# |
May 25th 2021, 23:11 |
ndm |
Your return value from the parent method will vanish into the void, as your overwritten method makes no use of it. You need to check if `parent::beforeFilter()` returns something, and then return that in your overwritten method. |
# |
May 25th 2021, 23:10 |
ljolley |
so controller action errors, and redirect doesn't happen. |
# |
May 25th 2021, 23:09 |
ljolley |
but the controller action is looking for `$session->read('Admin.organization_id')` |
# |
May 25th 2021, 23:09 |
ljolley |
again. redirect happens if I clear out the controller action |
# |
May 25th 2021, 23:08 |
ljolley |
is that correct? |
# |
May 25th 2021, 23:08 |
ljolley |
the code above is sitting in the `beforeFilter` in the `AppController`. It's literally the only thing in there ATM. In the controller, I have this: ```public function beforeFilter(EventInterface $event) { parent::beforeFilter($event); }``` |
# |
May 25th 2021, 23:06 |
ndm |
Either your `beforeFilter()` is not being invoked (maybe you've overwritten it incorrectly), or the conditions are not being fulfilled, ie the redirect is not being invoked. |
# |
May 25th 2021, 22:54 |
ljolley |
Looks like if I put the same check in the controller action, it works. but it's much more efficient and easier to maintain if I can have it just run in the `beforeFilter` |
# |
May 25th 2021, 22:45 |
ljolley |
regardless, I don't need the controller action to run. |
# |
May 25th 2021, 22:43 |
ljolley |
not sure why. on actions that would fall under the same criteria, the redirect works - but there's no showstoppers in the controller action |
# |
May 25th 2021, 22:43 |
ljolley |
this runs in the beforeFilter but it executes the controller action before the redirect happens |
# |
May 25th 2021, 22:41 |
ljolley |
right. |
# |
May 25th 2021, 22:38 |
greg138 |
`beforeFilter` does run before your controller's action starts. |
# |
May 25th 2021, 22:34 |
ljolley |
looks like the `return` isn't returning? |
# |
May 25th 2021, 22:32 |
ljolley |
working through this some more, it looks like the redirect is triggered, but the page errors out in the controller because it's expecting `$session->read('Admin.organization_id');` Is there a way to force the redirect in the `beforeFilter` before it hits controller logic? |
# |
May 25th 2021, 22:25 |
ljolley |
top redirect under `//REDIRECT TO ORGANIZATION DASHBOARD` works fine. |
# |
May 25th 2021, 22:25 |
slackebot |
== false) { //REDIRECT TO MAIN DASHBOARD $this->Flash->admin_info(__('Not an out action.')); return $this->redirect(['controller'=>'Dashboard','action'=>'main','prefix'=>'Admin']); } }``` |
# |
May 25th 2021, 22:25 |
slackebot |
$this->Flash->admin_info(__('Not an in action.')); return $this->redirect(['controller'=>'Dashboard','action'=>'organization','prefix'=>'Admin']); } } else if(!$session->check('Admin.organization_id')) { //IF UNLOADED $access = $this->Access->actionCheck($this->request->getParam('controller'),$this->request->getParam('action'),'out'); if($access |
# |
May 25th 2021, 22:25 |
ljolley |
``` //CHECK THAT A CONTROLLER AND ACTION IS ACCESSIBLE DEPENDING ON IF THE USER IS LOADED INTO AN ORGANIZATION if($session->check('Admin.organization_id')) { //IF LOADED $access = $this->Access->actionCheck($this->request->getParam('controller'),$this->request->getParam('action'),'in'); if($access == false) { //REDIRECT TO ORGANIZATION DASHBOARD |
# |
May 25th 2021, 22:24 |
ljolley |
I have a check happening in the `AppController` `beforeFilter` and for whatever reason, the redirect doesn't trigger. |
# |
May 25th 2021, 22:23 |
ljolley |
is there anything that would cause a redirect `$this->redirect()` to not work? |
# |
May 25th 2021, 22:10 |
jojomartius |
sounds good @ndm thanks! |
# |
May 25th 2021, 22:09 |
ndm |
@jojomartius That's controlled by the route class. Check your routes config for `setRouteClass()` or `routeClass()` calls, they might be missing, leaving you with the default route class that maps the path as-is. https://github.com/cakephp/app/blob/4.2.2/config/routes.php#L27-L45 |