Domanda

Ho un modello di e-mail in una vista e voglio scrivere un processo che è ConsoleApplication che prepara email da inviare. Siccome è ConsoleApplication non ho accesso al controllore. E 'un modo per rendere un punto di vista?

È stato utile?

Soluzione

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 email da viste / email .

Altri suggerimenti

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_);
    }
}   

?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top