2012-12-12 18 views
5

Sto provando a caricare l'estensione Yii Bootstrap solo nel modulo admin ma non funziona. Sto assumendo che ho bisogno di precaricarlo o avviarlo in qualche modo ... Grazie!caricamento di Yii Bootstrap solo in un modulo

class AdminModule extends CWebModule 
    { 
     public function init() 
     { 
      // import the module-level models and components 
      $this->setImport(array(
       'admin.models.*', 
       'admin.components.*', 
       'ext.bootstrap.components.Bootstrap', 
      )); 
     } 

     public function beforeControllerAction($controller, $action) 
     { 
      if(parent::beforeControllerAction($controller, $action)) 
      { 
         $this->layout = 'admin';     
         return true; 
      } 
      else 
       return false; 
     } 
    } 
+1

in che modo è non funziona? –

+0

non carica il css ecc ... – keeg

risposta

10

Ci sono 4 modi diversi per farlo:

  1. aggiungere la configurazione alla configurazione del app (protetto/config/main.php):

    'modules'=>array(
        'admin'=>array(
         'preload'=>array('bootstrap'), 
         'components'=>array(
          'bootstrap'=>array(
           'class'=>'ext.bootstrap.components.Bootstrap' 
         ) 
        ), 
    // ... other modules ... 
    )  
    
  2. Precaricarlo nel init:

    public function init() 
    { 
        // import the module-level models and components 
        $this->setImport(array(
         'admin.models.*', 
         'admin.components.*', 
         // 'ext.bootstrap.components.Bootstrap', // this will go to app config for components 
        )); 
        Yii::app()->getComponent('bootstrap');// this does the loading 
    } 
    
  3. precarico in init un altro modo:

    public function init() 
    { 
        // import the module-level models and components 
        $this->setImport(array(
         'admin.models.*', 
         'admin.components.*', 
        )); 
    
        $this->configure(array(
          'components'=>array(
           'bootstrap'=>array(
            'class'=>'ext.bootstrap.components.Bootstrap' 
           ) 
          ) 
        )); 
        $this->getComponent('bootstrap'); 
    } 
    
  4. precarico in init ancora un altro modo:

    public function init() 
    { 
        // import the module-level models and components 
        $this->setImport(array(
         'admin.models.*', 
         'admin.components.*', 
        )); 
    
        $this->configure(array(
          'preload'=>array('bootstrap'), 
          'components'=>array(
           'bootstrap'=>array(
            'class'=>'ext.bootstrap.components.Bootstrap' 
           ) 
          ) 
        )); 
        $this->preloadComponents(); 
    } 
    
+1

Grazie! Questo è esattamente ciò di cui avevo bisogno! – keeg

+0

Ricevo ancora l'errore La proprietà "CWebApplication.bootstrap" non è definita. quando si utilizza uno dei due esempi :(È perché memorizzo file di bootstrap all'interno delle estensioni del modulo? – dzona

+0

@dzona, puoi farlo anche se hai bootstrap all'interno della directory _extensions_ di un modulo (l'ho appena provato). maggiori dettagli sul codice che hai (e sulla linea che genera quell'errore) e sulla configurazione delle tue directory, e anche sulla versione del tuo bootstrap, per me è in grado di indicare con precisione il problema, altrimenti vedi se hai accesso corretto all'estensione (usato alias corretto - 'module_name.extensions.bootstrap.components.Bootstrap'), ovunque si stia tentando di inizializzare la classe dell'estensione. –

1

codice realmente lavorando: nella funzione init modulo appena incolla il seguente codice:

Yii::setPathOfAlias('bootstrap', Yii::getPathOfAlias('ext.bootstrap')); 
Yii::app()->setComponent('bootstrap', array('class'=>'bootstrap.components.Bootstrap')); 
2

Quando si configura quanto segue nella configurazione principale (protetto/config/main.php), ad esempio come:

'admin' => array(
     'preload'=>array('bootstrap'), 
     'components'=>array(
      'bootstrap' => array(
       'class' => 'bootstrap.components.Bootstrap', 
       'responsiveCss' => true, 
      ), 
     ), 
) 

Quindi, è possibile utilizzare come componente

$bootstrap = $this->getModule()->bootstrap; // with $this is a current controller. 

Per definire questo componente del modulo componente principale, è necessario impostare Componente in init() della classe Module:

// Set main component `bootstrap` instead of CController->getModule()->bootstrap 
app()->setComponent('bootstrap', $this->bootstrap); 
0
protected/config/main.php 

'modules'=>array(
    'admin'=>array(
     'preload'=>array('bootstrap'), 
     'components'=>array(
      'bootstrap'=>array(
       'class'=>'ext.bootstrap.components.Bootstrap' 
     ) 
    ), 

)  

precarico nel init:

public function init() 
{ 
    // import the module-level models and components 
    $this->setImport(array(
     'admin.models.*', 
     'admin.components.*', 
     // 'ext.bootstrap.components.Bootstrap', // this will go to app config for components 
    )); 
    Yii::app()->getComponent('bootstrap');// this does the loading 
} 

Se non funziona quindi incollare l'URL in quel file, che si formano utilizzano bootstrap

<link rel="stylesheet" type="text/css" href="/pojects/fcorginal/assets/b2e88ad5/bootstrap/css/bootstrap.min.css" /> 
Problemi correlati