PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 1, 2022

[FIXED] How are these twig variables initialized or injected

 January 01, 2022     cakephp, cakephp-3.0, twig     No comments   

Issue

I'm looking at form.twig and I see the following line near the top of the file:

{% set fields = Bake.filterFields(fields, schema, modelObject) %}

If I attempt to use the variable schema in another twig file (ex. entity.twig), it fails. Where are these variable initialized/injected?

Edit #1

All variables available in entity.twig

/tmp/cache/twigView/f9/f9e579e257fbf8646e4fb36344bec8b65599b3bdf9e4b72e538604521bd173e1.php (line 33)
########## DEBUG ##########
[
    (int) 0 => 'associations',
    (int) 1 => 'associationInfo',
    (int) 2 => 'primaryKey',
    (int) 3 => 'displayField',
    (int) 4 => 'table',
    (int) 5 => 'propertySchema',
    (int) 6 => 'fields',
    (int) 7 => 'validation',
    (int) 8 => 'rulesChecker',
    (int) 9 => 'behaviors',
    (int) 10 => 'connection',
    (int) 11 => 'hidden',
    (int) 12 => 'name',
    (int) 13 => 'namespace',
    (int) 14 => 'plugin',
    (int) 15 => 'pluginPath',
    (int) 16 => 'entity'
]

Solution

The variables are created in the relevant bake task. For templates that's \Bake\Shell\Task\TemplateTask, and the variables are generated in its _loadController() method.

Entities are being baked via \Bake\Shell\Task\ModelTask, and it generates a different set of view variables, one that fits the needs of tables/entities, see the getTableContext() method (shared by tables and entities), and the bakeEntity() method.

You can always use the getVars() function in your twig template to get a list of all currently set view variables:

{% do getVars()|debug %}


Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing