Yii Framework Forum: Generate Import path dari database - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Generate Import path dari database Rate Topic: -----

#1 User is offline   Sidney Shaw 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 17-August 09

Posted 17 August 2009 - 12:53 PM

Hallo...
langsung aja...

Di file index.php ada kode berikut:
$yii=dirname(__FILE__).'/../../library/yii/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

require_once($yii);

$conf = include($config);
$myWebApp = new CWebApplication($conf);
$myWebApp->run();


variabel config tersebut, potongan isinya sbb (dari file main.php):
// autoloading model and component classes
	'import'=>array(
		'application.models.*',
		'application.components.*',
		
		'pogostick.base.*',
		'pogostick.behaviors.*',
		'pogostick.components.*',
		'pogostick.events.*',
		'pogostick.helpers.*',
		'pogostick.widgets.*',
		'pogostick.widgets.jqui.*'
	)


Gimana caranya biar import array pogostick, itu diload dari database saja?

jadi di index.php ada proses baca database utk populate variabel $myPogo jadi gini:
$yii=dirname(__FILE__).'/../../library/yii/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

require_once($yii);

$conf = include($config);

//variabel ini nanti diambil dari tabel database... 
//(cuma klo dari index.php ngak tau gimana akses tabelnya)
$myPogo = array(
	'pogostick.base.*',
	'pogostick.behaviors.*',
	'pogostick.components.*',
	'pogostick.events.*',
	'pogostick.helpers.*',
	'pogostick.widgets.*',
	'pogostick.widgets.jqui.*'
);

//abis keisi, digabung ama import utama....
$conf['import'] = array_merge($conf['import'],$myPogo);

//baru jalanin webnya
$myWebApp = new CWebApplication($conf);
$myWebApp->run();


sedangkan isi main.php jadi:
// autoloading model and component classes
	'import'=>array(
		'application.models.*',
		'application.components.*'


Thanks for any helps...
0

#2 User is offline   Sidney Shaw 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 17-August 09

Posted 17 August 2009 - 11:40 PM

Saya coba dengan cara begini ternyata bisa, tapi bukan cara yang bagus sich.....
mohon sarannya...
//file: index.php
$yii=dirname(__FILE__).'/../../library/yii/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

require_once($yii);
$conf = include($config);

//buka koneksi database
$connection=new CDbConnection(
	$conf['components']['db']['connectionString'],
	$conf['components']['db']['username'],
	$conf['components']['db']['password']
);
$connection->setActive(true);

//ambil datanya
$command=$connection->createCommand("SELECT * FROM sys_imports");
$reader=$command->query();

//parsing ke variabel
foreach($reader as $row){
	$myPogo[] = $row['i_name']	
}
$connection->setActive(false);

$conf['import'] = array_merge($conf['import'],$myPogo);

$myWebApp = new CWebApplication($conf);
$myWebApp->run();


//file: main.php
...
// autoloading model and component classes
	'import'=>array(
		'application.models.*',
		'application.components.*'
	),
...

0

#3 User is offline   Alfian 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 08-September 09
  • Location:Djogjakarta

Posted 08 September 2009 - 08:36 PM

saya menggunakan kode berikut, untuk mengambil konfigurasi dari Db :
// file : Yii.php
require(dirname(__FILE__).'/../../framework/YiiBase.php');

class Yii extends YiiBase
{
    public static function createWebApplication($config=null)
    {
        $app = new CWebApplication($config);
        $app->setParams(self::_getParams($app->db));
        $app->setModules(self::_getModules($app->db));
       
        Yii::app()->sourceLanguage = Yii::app()->params['language'];
	return $app;
    }

    private static function _getParams($db)
    {
        $params = array();
        $data = $db->createCommand("SELECT * FROM app_params")->queryAll();

        foreach($data as $item)
	{
		$params[$item['param']] = $item['value'];
	}

        return $params;
    }

    private static function _getModules($db)
    {
        $modules = array();
        $data = $db->createCommand("SELECT * FROM app_modules WHERE is_active='Y'")->queryAll();

        foreach($data as $item)
	{
	     $modules[$item['name']] = self::_unserializeData($item['parameters']);
	}

        return $modules;
    }

    private static function _unserializeData($str)
    {
        $q = array();

        $arr = explode(';',$str);

        foreach($arr as $i)
        {
            if(empty($i))
                continue;

            $arrD = explode(':',$i);
            $q[$arrD[0]]=$arrD[1];
        }

        return $q;
    }
}


untuk file index.php nya
// change the following paths if necessary
$yii=dirname(__FILE__).'/appsystem/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

// remove the following line when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);

require_once($yii);
Yii::createWebApplication($config)->run();


Untuk file Yii.php nya mendingan diluar folder framework, biar ga ketimpa pas update versi baru ..
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users