Loading from Mysql Confings

#1
[eluser]pisio[/eluser]
Hi all.
I wonna ask you , how i can get from mysql data and set it in same global varibian.
Code:
CREATE TABLE IF NOT EXISTS `config` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` text COLLATE utf8_unicode_ci NOT NULL,
  `value` text COLLATE utf8_unicode_ci NOT NULL,
  `discription` text COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5 ;


INSERT INTO `config` (`id`, `name`, `value`, `discription`) VALUES
(1, 'image_dir', './images/', 'Пътя  за качване на снимки'),
(2, 'result_per_page', '20', 'Резултати на страница'),
(3, 'subtitle_directory', './subs/', 'Пътя за  качване на субтитрите'),
(4, 'avatar_dir', './images/avatars/', 'Пътя до аватарите на потребителите');

a = Code to get confings
b = user/edit exp ....
c = view page for user/edit

And now i can use data from "A" in "B" and "C" , like as
$this->db->get_where and $this->load->view



I'm sorry for my bad english. If you don't understand me don't wory ;p be happy Big Grin

#2
[eluser]danmontgomery[/eluser]
Code:
$config = $this->db->get('config');
if($config && $config->num_rows()) {
    foreach($config->result() as $key => $value) {
        $this->config->set_item($key, $value);
    }
}

#3
[eluser]elmne[/eluser]
If you are concerned about your english or cannot understand some of the replies, try using
Quote:translate.google.com

I used it to view some of your comments and this is what i got

Quote:Bulgarian
'Path to upload photos - 'Пътя за качване на снимки
Way to upload photos - Пътя за качване на снимки

'Results page' - 'Резултати на страница'
Results per page - Резултати на страница

'Path to upload subtitles' - 'Пътя за качване на субтитрите'
Way to upload subtitles - Пътя за качване на субтитрите

'The road to the avatars of users' - 'Пътя до аватарите на потребителите'
Path to the avatars of users - Пътя до аватарите на потребителите

Just paste any text into the field and you will see the translation immediately.

#4
[eluser]pisio[/eluser]
[quote author="elmne" date="1277407561"]If you are concerned about your english or cannot understand some of the replies, try using
Quote:translate.google.com

I used it to view some of your comments and this is what i got

Quote:Bulgarian
'Path to upload photos - 'Пътя за качване на снимки
Way to upload photos - Пътя за качване на снимки

'Results page' - 'Резултати на страница'
Results per page - Резултати на страница

'Path to upload subtitles' - 'Пътя за качване на субтитрите'
Way to upload subtitles - Пътя за качване на субтитрите

'The road to the avatars of users' - 'Пътя до аватарите на потребителите'
Path to the avatars of users - Пътя до аватарите на потребителите

Just paste any text into the field and you will see the translation immediately.[/quote]



The text is not important.
Important is how to make data in same global for the site variabian.

#5
[eluser]elmne[/eluser]
Since you want to put values from database to global variables so that the values are accessible to all users, look at this post

ellislab.com/forums/viewthread/89488/

Someone there used a workaround.


But if it's per user and not all users, you could use sessions.

----


Try looking at this post where someone used constants instead of globals
Quote:http://stackoverflow.com/questions/25271...l-variable

I ran into a similar problem earlier today. I found that an easier way, rather than globals, was to use constants. You can define a constants file that will load from your index.php file:

Code:
// Include additional constants
$defines_file = 'includes/defines.php';
if (file_exists($defines_file))
{
    require_once($defines_file);
}
Then you can add your constants to the defines.php file:

Code:
define(MY_CONSTANT,'my constant info');
This way they will be available in any file throughout the system either directly: echo MY_CONSTANT; or you can assign them to variables.

I decided this way would be easier for me as I would only have 1 location to go to when/if I needed to change the constants.

More: http://ellislab.com/forums/viewthread/56981/#280205

also look at codeignitor.com/user_guide/libraries/loader.html

you can use this to load your variables as you will find a description on that page that states
Quote:
Code:
$this->load->vars($array)
This function takes an associative array as input and generates variables using the PHP extract function. This function produces the same result as using the second parameter of the $this->load->view() function above. The reason you might want to use this function independently is if you would like to set some global variables in the constructor of your controller and have them become available in any view file loaded from any function. You can have multiple calls to this function. The data get cached and merged into one array for conversion to variables.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.