# |
Jul 5th 2017, 23:17 |
jarard01 |
ok that works - so I was overcooking it |
# |
Jul 5th 2017, 23:14 |
jeremyharris |
(that’s what you gave me anyway) |
# |
Jul 5th 2017, 23:14 |
jeremyharris |
the name of your templates file in config/ |
# |
Jul 5th 2017, 23:13 |
jarard01 |
that will work, what is 'templatesConfig' in your example |
# |
Jul 5th 2017, 23:13 |
jeremyharris |
for a per-form basis |
# |
Jul 5th 2017, 23:13 |
jarard01 |
I want to be able to apply certain templlates to different forms |
# |
Jul 5th 2017, 23:13 |
jeremyharris |
you can also use $this->Form->create($context, [‘templates’ => ‘templatesConfig’]) |
# |
Jul 5th 2017, 23:12 |
jarard01 |
ok so I have that already, but because it is in AppView.php the template is applied to all forms |
# |
Jul 5th 2017, 23:12 |
jeremyharris |
in the example in the book, it loads the templates when the helper is loaded |
# |
Jul 5th 2017, 23:11 |
jeremyharris |
https://book.cakephp.org/3.0/en/views/helpers/form.html#customizing-the-templates-formhelper-uses |
# |
Jul 5th 2017, 23:10 |
jarard01 |
is there an example any where? |
# |
Jul 5th 2017, 23:09 |
jeremyharris |
you can pass the name of your template file to FormHelper on create and it will merge them in |
# |
Jul 5th 2017, 23:08 |
jeremyharris |
yep you’re on the right track |
# |
Jul 5th 2017, 23:08 |
jarard01 |
I have a template that I need to use in severla places |
# |
Jul 5th 2017, 23:08 |
jeremyharris |
templates are not loaded into Configure |
# |
Jul 5th 2017, 23:08 |
jeremyharris |
see: https://book.cakephp.org/3.0/en/views/helpers/form.html#customizing-the-templates-formhelper-uses |
# |
Jul 5th 2017, 23:07 |
jarard01 |
but it shouldn't be null should it? |
# |
Jul 5th 2017, 23:07 |
jeremyharris |
that’s not quite how they work, you load them up into the form helper |
# |
Jul 5th 2017, 23:07 |
jarard01 |
but it returns NULL |
# |
Jul 5th 2017, 23:07 |
jarard01 |
then I debug: $this->set('form_templates', Configure::read('Templates')); |
# |
Jul 5th 2017, 23:07 |
jarard01 |
in my controller: use Cake\Core\Configure; |
# |
Jul 5th 2017, 23:06 |
jarard01 |
I set my template in that file |
# |
Jul 5th 2017, 23:06 |
jeremyharris |
that particular one doesn’t ship with cake, if that’s what you’re wondering |
# |
Jul 5th 2017, 23:06 |
jeremyharris |
jarard01 form templates are stored in config, yes |
# |
Jul 5th 2017, 23:06 |
jeremyharris |
that’s good to hear. too many clients want corners cut when it comes to testing |
# |
Jul 5th 2017, 23:06 |
urowe |
So we're writing tests and stuff |
# |
Jul 5th 2017, 23:06 |
urowe |
Yeah, I got this new project, the client is very invested in doing it the right way |
# |
Jul 5th 2017, 23:06 |
jarard01 |
is this standard cake: config/templatesConfig.php |
# |
Jul 5th 2017, 23:05 |
jeremyharris |
happy testing :tada: |
# |
Jul 5th 2017, 23:05 |
urowe |
Thanks a lot! |
# |
Jul 5th 2017, 23:05 |
urowe |
You saved the day my friend |
# |
Jul 5th 2017, 23:04 |
jeremyharris |
it’s one of my plugins that has tests with fixtures, pretty small so it’s easy to understand |
# |
Jul 5th 2017, 23:04 |
jeremyharris |
np, take a look at this: https://github.com/jeremyharris/cakephp-lazyload/tree/master/tests |
# |
Jul 5th 2017, 23:04 |
urowe |
Thanks |
# |
Jul 5th 2017, 23:04 |
jeremyharris |
indeed! and since they are dropped and re-created on each test case, you always know what state your DB is in at the start of each test |
# |
Jul 5th 2017, 23:04 |
urowe |
I hand't really understood how they worked |
# |
Jul 5th 2017, 23:03 |
urowe |
Oh that's very cool |
# |
Jul 5th 2017, 23:03 |
jeremyharris |
so you would need a UsersFixture and a RolesFixture. Whatever records exist in those fixtures would be loaded on each test case. Then you can call your app code that does the check, and it will read from the test database (now populated with those records) |
# |
Jul 5th 2017, 23:02 |
urowe |
In case let's say I want to verify a user has a role that already exists in the database |
# |
Jul 5th 2017, 23:02 |
jeremyharris |
the fixtures in cakephp set up your database state on each test method, that’s all |
# |
Jul 5th 2017, 23:02 |
jeremyharris |
you can use a test method with a dataProvider side by side with fixtures - they work fine together |