File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,34 @@ into the SQL query. You should use classic SQL parameters for this. This means t
135
135
136
136
Want to know more? <a class =" btn btn-primary " href =" doc/magic_twig.md " >Check out the MagicTwig guide!</a >
137
137
138
+ <a name =" twig " ></a >
139
+ Use Twig templating in your SQL queries!
140
+ ----------------------------------------
141
+
142
+ Discarding unused parameters and auto-joining keys is not enough? You have very specific needs? Say hello to
143
+ Twig integration!
144
+
145
+ Using Twig integration, you can directly add Twig conditions right into your SQL.
146
+
147
+ ``` php
148
+ use Mouf\Database\MagicQuery;
149
+
150
+ $sql = "SELECT users.* FROM users {% if isAdmin %} WHERE users.admin = 1 {% endif %}";
151
+
152
+ $magicQuery = new MagicQuery();
153
+ // By default, Twig integration is disabled. You need to enable it.
154
+ $magicQuery->setEnableTwig(true);
155
+
156
+ $completeSql = $magicQuery->build($sql, ['isAdmin' => true]);
157
+ // Parameters are passed to the Twig SQL query, and the SQL query is returned.
158
+ ```
159
+
160
+ <div class =" alert alert-info " ><strong >Heads up!</strong > The Twig integration cannot be used to insert parameters
161
+ into the SQL query. You should use classic SQL parameters for this. This means that instead if writing
162
+ <code >{{ id }}</code >, you should write <code >: id </code >.</div >
163
+
164
+ Want to know more? <a class =" btn btn-primary " href =" doc/magic_twig.md " >Check out the MagicTwig guide!</a >
165
+
138
166
Is it a MySQL only tool?
139
167
------------------------
140
168
You can’t perform that action at this time.
0 commit comments