Welcome Guest, Not a member yet? Register   Sign In
Using a sql alias within a model's find() function
#3

PHP Code:
$locale service('request')->getLocale();
// validate & sanitize $locale
"select test_{$locale} AS test FROM tblzz;" 
Validate/sanitize locale before plugging anything into a query string like that to prevent SQL injection attacks and/or use appropriate QueryBuilder methods.
However, the more appropriate way to do this would be to create a locale column and then modify your query to be:
PHP Code:
"select test FROM tblzz WHERE locale={$locale};" 

CodeIgniter isn't opinionated on how you handle localization when using a database, so the way to do is left up to the developer. If your table is primarily static and the information won't change, you're better off using the flat file approach that's already supported within CodeIgniter. You can store the data as a serialized array (if for some reason you need it raw) or with html already embedded.
Reply


Messages In This Thread
RE: Using a sql alias within a model's find() function - by grimpirate - 04-07-2025, 09:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB