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

Wednesday, February 16, 2022

[FIXED] how to get all the languages array in yii1?

 February 16, 2022     php, yii, yii1.x     No comments   

Issue

the directory structure is like this

modules/
       /module1
              /messages/
                       /en
                          /admin.php
                          /profile.php
                       /ru/
                          /admin.php
                          /profile.php

       /module2/
              /messages/
                       /en
                          /account.php
                          /stats.php
                       /ru
                          /account.php
                          /stats.php

each of thos php files has a huge array inside where by the array contains a key value pair of the text strings like e.g

return array(
'hello' => 'aloha'
);

so how to get the arrays in each files ?


Solution

you may implement new method to achieve this using glob() php function

$language = 'en';

foreach (glob('modules/*/messages/' . $language . '/*') as $file) {
    echo "$file\n";
}

Output :

modules/module1/messages/en/admin.php
modules/module1/messages/en/profile.php
modules/module2/messages/en/admin.php
modules/module2/messages/en/profile.php

to return arrays from inside those files :

$language = 'en';
$arrays = [];
foreach (glob('modules/*/messages/' . $language . '/*') as $file) {
    $arrays[] = require_once "$file";
}

print_r($arrays);


Answered By - hassan
  • 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