2

Laravel 3 を使用してコンテンツ管理フレームワークの作業を始めたところです。これは、データベース駆動型のアプリとして設計されていません (後で追加される可能性があります)。これは、静的な Web サイトを作成するための簡単で SEO に適した方法を求める Web デザイナー向けに設計されています。

簡単に言えば、デザイナーはフォルダー構造を操作して、デフォルト サイトとその他の [オプション] サイト (Drupal のようなマルチサイト フレームワークにする) を作成するだけで済みます。

現在、構造は次のように設計されています (まだ実装されていません。これは単なるアイデアです。これは、Laravel の標準的なパス構造の変更でもあります)。

public[_html]
root
    app // application folder
    bundles
    sites
        sites.json // used to determine the default site, and register any others
        {site-slug}
            info.json
            content // for page content that inherits a layout
                {page-slug}
                    info.json
                    content.blade.php
            layouts // site layouts: headers, footers, etc.
    stores // storage folder
    system // laravel folder

現在の私の主な問題は次のとおりです。View クラスを拡張して、プレフィックスviewsを使用せずに標準フォルダーの外を見る方法がわかりません。path:

これを行う最良の方法は何ですか?

おそらく、このタスクを簡単にする別のテンプレート エンジンはありますか? Laravel 3 に適した HAML エンジンはありますか?

注: Markdown を利用するコンテンツ バンドルがあることは知っていますが、それは私が探しているものではありません。

ここで何か助けていただければ幸いです。

4

2 に答える 2

2

views.php 構成ファイルでは、配列に含めたいすべてのディレクトリを追加できるはずです

編集

申し訳ありませんが、これはlaravel 4用です。ビュークラスを拡張し、パスの配列を検索するようにします.View::pathメソッドです。構成ファイルを使用してこの配列を設定できるため、パスの呼び出しは Config::get('views') になります

私の解決策

少し前、私はプロジェクトに取り組んでいて、コア ファイルの変更を回避するソリューションを思いつきました。

application/start.php で

Event::listen(View::loader, function($bundle, $view)
{
    foreach (Config::get('views', array()) as $path) {
        if($file = View::file($bundle, $view, $path))
            return $file;
    }

    return View::file($bundle, $view, Bundle::path($bundle).'views');
});

application/config/views.php 内 (これを作成する必要があります)

return array(
    path('app').'../myviews',
);

これで、このファイルに任意の数のディレクトリを追加できるようになり、デフォルトのビュー ディレクトリがチェックされる前にそれらがチェックされます。

于 2013-02-12T16:58:58.673 に答える
-1

私はこれを使用しています:

ミドルウェア setDB を作成します。

namespace App\Http\Middleware; 

use Cookie;  
use Config;  
use Closure;  
use DB;  
use App\User;  
use App\Common;  
use Auth;  
use Session;  
use View;  
use Illuminate\Contracts\Foundation\Application;   

class SetDB
{  
   public function __construct(Application $app){   
       $this->app=$app;  
   }  
   public function handle($request, Closure $next)  
   {  
        $server=$_SERVER["SERVER_NAME"];  
        $paths = 'resources/views';    
        $asset = 'public';  
        $result=DB::connection('mysql2')->table('mst_editor_database_info')->where("paths",$server)->first();   
        DB::disconnect(env('DB_DATABASE'));

        if(count($result) > 0){ 

            $dbname=$result->dbname;   
            $paths = 'themes/'.$result->paths.'/views';   
            Session::put('paths',$paths);  
            Session::put('asset','themes/'.$result->paths.'/assets');   
            Config::set('database.connections.mysql', array(
                   'driver' => 'mysql',
                   'host' => env('DB_HOST'),
                   'port' => env('DB_PORT'),
                   'database' =>$dbname,
                   'username' => 'username',
                'password' => 'password',
                'charset' => 'utf8',
                'collation' => 'utf8_unicode_ci',
                'prefix' => '',
            ));
            DB::reconnect('mysql');

        }else{

            DB::disconnect('mysql');
            Config::set('database.connections.mysql', config('database.connections.mysql2'));
            DB::reconnect('mysql');
            Session::put('paths',$paths);
            Session::put('asset',$asset);
        }
        Common::setTheme();
        Config::set('site.asset', Session::get('asset'));
        return $next($request);
    }
}

クラス App\Common.php を作成します。

namespace App;
use Config;
use Session;
use Illuminate\Database\Eloquent\Model;
use View;

class Common extends Model
{
   public static function setTheme(){
       Config::set('view.paths', Session::get('paths'));
       View::addNamespace('Theme', Session::get('paths'));
    }
}

名前空間テーマの使用:

return View::make('Theme::welcome');

kernel.php にミドルウェアを登録します。

protected $middlewareGroups = [
  'web' => [
    \App\Http\Middleware\SetDB::class,
  ]
];

config/database.php でデフォルトのデータベース接続を設定します。

'connections' => [

'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST'),
'port' => env('DB_PORT'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],

'mysql2' => [
'driver' => 'mysql',
'host' => env('DB_HOST'),
'port' => env('DB_PORT'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],

],

config/view.php を設定します。

    'paths' => [base_path('/')],

テンプレート フォルダーを作成する

themes/{paths}/views
于 2016-12-21T07:50:04.473 に答える