# Change bake table className for users

**URL:** <https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229>\
**Category:** Need Help\
**Created:** [May 19, 2023, 4:06am UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229 "2023-05-19T04:06:04Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomasg](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@thomasg](https://discourse.cakephp.org/u/thomasg)\
**Post date:** [May 19, 2023, 4:06am UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229/1 "2023-05-19T04:06:04Z")

</div>

I want to change the bake template for table when the className = Users I want className to be ‘className’ =\> Configure::read(‘Users.table’), and then add also use Cake\Core\Configure; to the top.

Anyone know how to edit the table.twig?

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [May 19, 2023, 8:19am UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229/2 "2023-05-19T08:19:53Z")

</div>

You can create a custom bake theme like explained here  
[https://book.cakephp.org/bake/2/en/development.html#creating-a-bake-theme](https://book.cakephp.org/bake/2/en/development.html#creating-a-bake-theme)

---

<div class="post-metadata">

**Author:** ![thomasg](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@thomasg](https://discourse.cakephp.org/u/thomasg)\
**Post date:** [May 19, 2023, 8:46am UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229/3 "2023-05-19T08:46:33Z")

</div>

My question a bit more specific then that…

---

<div class="post-metadata">

**Author:** ![thomasg](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@thomasg](https://discourse.cakephp.org/u/thomasg)\
**Post date:** [May 19, 2023, 8:59am UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229/4 "2023-05-19T08:59:57Z")

</div>

This is what is in table.twig

```auto
{%- if associations.belongsTo or associations.hasMany or associations.belongsToMany %}

{% endif %}

{%- for type, assocs in associations %}
    {%- for assoc in assocs %}
        {%- set assocData = [] %}
        {%- for key, val in assoc %}
            {%- if key is not same as('alias') %}
                {%- set assocData = assocData|merge({(key): val}) %}
            {%- endif %}
        {%- endfor %}
        $this->{{ type }}('{{ assoc.alias }}', {{ Bake.exportArray(assocData, 2)|raw }});
        {{- "\n" }}
    {%- endfor %}
{% endfor %}
    }
{{- "\n" }}

```

---

<div class="post-metadata">

**Author:** ![thomasg](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@thomasg](https://discourse.cakephp.org/u/thomasg)\
**Post date:** [May 19, 2023, 9:52am UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229/5 "2023-05-19T09:52:27Z")

</div>

I got something like this, but that doesnt work for the Configure::read part, if i just write 'Someclass its ok… how to get Configure::read there?

{% if key == ‘className’ and val == ‘Myplugin.Users’ %}  
{% set val = Configure::read(‘Users.table’) %}  
{% endif %}

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [May 19, 2023, 9:53am UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229/6 "2023-05-19T09:53:46Z")

</div>

I am not really sure what you are trying to achieve with this `Users.table` config value.  
Do you have multiple table classes for the same table? Because the `className` in the association config only needs to be set when the association name is not the same as the class name (without the Table suffix)

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [May 19, 2023, 9:54am UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229/7 "2023-05-19T09:54:08Z")

</div>

> [@thomasg](#):
>
> {% set val = Configure::read(‘Users.table’) %}

That can’t work. You are inside twig, not PHP.

---

<div class="post-metadata">

**Author:** ![thomasg](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@thomasg](https://discourse.cakephp.org/u/thomasg)\
**Post date:** [May 19, 2023, 9:56am UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229/8 "2023-05-19T09:56:48Z")

</div>

I want it to print Configure::read(… in the baked file… exactly. Not actualy looking up the value in the template.

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [May 19, 2023, 9:59am UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229/9 "2023-05-19T09:59:19Z")

</div>

then just write it as is without any twig syntax,  
so like

```auto
$myVarInGeneratedTemplate = Configure::read(‘Users.table’);

```

and not

```auto
{% set val = Configure::read(‘Users.table’) %}

```

Its like writing html in PHP outside of the `<?php ?>` tags.

Also you technically don’t need the use statement if you just use the FQCN like so

```auto
$myVarInGeneratedTemplate = \Cake\Core\Configure::read(‘Users.table’)

```

---

<div class="post-metadata">

**Author:** ![thomasg](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@thomasg](https://discourse.cakephp.org/u/thomasg)\
**Post date:** [May 19, 2023, 9:59am UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229/10 "2023-05-19T09:59:29Z")

</div>

{% set val = ‘Mytable’ %}

like this it will show ‘className’ =\> ‘Mytable’

I want ‘className’ =\> Configure::Read(‘Users.table’)

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [May 19, 2023, 10:06am UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229/11 "2023-05-19T10:06:56Z")

</div>

i see what you are trying to achieve. I am not really sure this can be done with the underlying [GitHub - brick/varexporter: A powerful alternative to var\_export(), which can export closures and objects without \_\_set\_state()](https://github.com/brick/varexporter) we are using [here](https://github.com/cakephp/bake/blob/2.x/src/View/Helper/BakeHelper.php#L160) via `Bake.exportArray(assocData, 2)`

---

<div class="post-metadata">

**Author:** ![thomasg](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@thomasg](https://discourse.cakephp.org/u/thomasg)\
**Post date:** [May 19, 2023, 10:08am UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229/12 "2023-05-19T10:08:13Z")

</div>

yeah thats what i was looking at also here

---

<div class="post-metadata">

**Author:** ![thomasg](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@thomasg](https://discourse.cakephp.org/u/thomasg)\
**Post date:** [May 19, 2023, 10:16am UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229/13 "2023-05-19T10:16:46Z")

</div>

guess ill need to change it manually each time I bake it…

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [May 19, 2023, 2:15pm UTC](https://discourse.cakephp.org/t/change-bake-table-classname-for-users/11229/14 "2023-05-19T14:15:23Z")

</div>

How often are you baking this one table class? I bake things to get started, and then just work with them after that.
