Hi
I use Extjs for front end and yii for back end of my application.
In one of views i have Extjs tabs that i have map in one of tabs, This tab created dynamically when user clicks on button,So i want to import js,css files of map only when it rendered.I call map via ajax when user click on button!.I use following code for this purpose but it can’t import js,css files to main view. I render map view with renderPartial method.
Main Controller that create main view of site!
public function actionIndex()
{
$cs = Yii::app()->getClientScript();
$cs->registerCssFile(Yii::app()->baseUrl.'/css/panel/history-panel.css',
CClientScript::POS_HEAD);
Yii::app()->clientScript->registerCoreScript("jquery");
/* Yii::app()->clientScript->registerScriptFile(
Yii::app()->baseUrl.'/js/OpenLayers.js'
,
CClientScript::POS_HEAD
);*/
$this->render('index');
}
I commented OpenLayers.js that used with map in this controller to test importing it via mapController that create map.
mapController action for creating map view
public function actionTest()
{
$cs = Yii::app()->getClientScript();
$cs = Yii::app()->getClientScript();
$cs->registerScriptFile( Yii::app()->baseUrl.'/js/OpenLayers.js',CClientScript::POS_HEAD);
Yii::app()->clientScript->registerScriptFile('http://maps.google.com/maps/api/js?sensor=false',
CClientScript::POS_HEAD);
$this->renderPartial('test');
}
but when i use above code to import OpenLayers.js that used with map, it doesn’t imported so commands like following code doesn’t works.
var map = new OpenLayers.map();
OpenLayers in above code doesn’t recognized with browser because OpenLayers.js doesn’t imported!
I call mapController via ajax with below code:
tabs.remove(tabs.getComponent(2));
tabs.insert(2,{
title:'Map',
loader: {
scripts: true,
autoLoad :true,
failure : function(){
alert('failed');
},
url: '<?php echo Yii::app()->createUrl('Map/test');?>'
}
});
Can’t i import js/css files when i use ajax or renderPartial rendered views?
Can i fix this problem?