Ern*_*nie 7 view laravel output laravel-4
在我看来,我很难尝试一些非常微不足道的事情.
我想创建一个视图,获取字符串内容并将其保存到xml文件中
这是我尝试的示例代码,但它将xml视图输出到浏览器
use Illuminate\Filesystem\Filesystem;
class ExportController extends BaseController {
function getIndex(){
$fs = new Filesystem();
$data = array();
$view = View::make('xml', $data);
$html = $view->render(); //outputs content to the browser
$fs->put("exercise.xml", $html);
}
}
Run Code Online (Sandbox Code Playgroud)
我在View API中找不到任何其他方法来获取内容,__ toString也在内部调用render函数.我在这里错过了什么吗?
编辑:这是我的完整导出控制器:我想将数据库中的练习导出到独立的html和XML文件.hickup位于我循环练习的底部.视图输出到浏览器,foreach停止
use Illuminate\Filesystem\Filesystem;
set_time_limit(0);
class ExportController extends BaseController {
function __construct(){
}
function getIndex($methodId = NULL, $exerciseId = NULL){
$base = base_path() . "/export/";
$playerPath = base_path() . "/public/preview/dist/";
$uploadsPath = base_path() . "/public/uploads/";
if($methodId ===NULL && $exerciseId === NULL){
$up = new Exception('Please provide a method-id or an exercise id');
throw $up;
}
//we make an array which holds all the exercises we have to export
$exercises = array();
//get all exercises for given methodId
if($methodId !== NULL){
$method = Method::with('categories.exercises')->find($methodId);
if($method == NULL) break;
foreach($method->categories as $category){
foreach($category->exercises as $exercise){
array_push($exercises, $exercise);
}
}
}
if($exerciseId != null){
$exercise = Exercise::find($exerciseId);
if($exercise != NULL) array_push($exercises, $exercise);
}
if(empty($exercises)){
$up = new Exception('No exercises could be found for given method/exercise');
throw $up;
}
//loop the exercises and publish like a charm
foreach($exercises as $exercise){
//determine destination
$path = $base . $exercise->getPath();
//check if path exists, if it does, wipe it out
$fs = new Filesystem();
if($fs->exists($path)){
$fs->deleteDirectory($path, true);
}
//copy player files
echo "copying " . $path . "<br />";
$fs->copyDirectory($playerPath, $path);
//copy resources
echo "copying resources " . $path . "<br />";
$fs->copyDirectory($uploadsPath . $exercise->id . "/", $path);
//save xml file
$content = Exercise::getXmlContent($exercise->id);
$fs->put($path . "exercise.xml", View::make('xml', $content));
}
}
}
Run Code Online (Sandbox Code Playgroud)
Ant*_*iro 11
要获取并保存您的HTML,您只需:
function getIndex(){
$fs = new Filesystem();
$data = array();
$fs->put("exercise.xml", View::make('xml', $data));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9379 次 |
| 最近记录: |