Ho un modello di posta elettronica in una vista e voglio scrivere un processo che è ConsoleApplication che prepara le email da inviare. Siccome è ConsoleApplication, non ho accesso al controller. È un modo per rendere una visualizzazione?visualizzazione rendering nell'applicazione console yii
6
A
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.
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_);
}
}
?>
c'è qualche buon modo per rendere da modello? o c'è un collegamento a CConsoleCommand attualmente lanciato? – liysd
Aggiungere questo metodo al comando della console. Puoi passare un array con $ this e il tuo modello a $ data parameter. –
downvote, nessun esempio di utilizzo fornito, che casino è sufficiente incollare nel comando – Tebe