2010-11-20 6 views

risposta

16

Ecco quello che io uso:

private function render($template, array $data = array()){ 
    $path = Yii::getPathOfAlias('application.views.email').'/'.$template.'.php'; 
    if(!file_exists($path)) throw new Exception('Template '.$path.' does not exist.'); 
    return $this->renderFile($path, $data, true); 
} 

Prende modello di e-mail da vista/e-mail.

+0

c'è qualche buon modo per rendere da modello? o c'è un collegamento a CConsoleCommand attualmente lanciato? – liysd

+0

Aggiungere questo metodo al comando della console. Puoi passare un array con $ this e il tuo modello a $ data parameter. –

+0

downvote, nessun esempio di utilizzo fornito, che casino è sufficiente incollare nel comando – Tebe

1

Se tutto il resto fallisce (come nel mio caso):

<?php 


    /** 
    * Renders a view file & returns result. 
    * @param string $_viewFile_ view file path 
    * @param array $_data_ optional data to be extracted as local view variables 
    * @param boolean $_return_ whether to return the rendering result instead of displaying it 
    * @return mixed the rendering result if required. Null otherwise. 
     */ 
public function myRenderPartial($_viewFile_,$_data_=null,$_return_=true) { 

    if(is_array($_data_)) 
     extract($_data_,EXTR_PREFIX_SAME,'data'); 
    else 
     $data=$_data_; 

    if($_return_) 
    { 
     ob_start(); 
     ob_implicit_flush(false); 
     require(YiiBase::getPathOfAlias("application.views").$_viewFile_.'.php'); 
     return ob_get_clean(); 
    } 
    else 
    { 
     require($_viewFile_); 
    } 
} 

?> 
Problemi correlati