0

カラビナjs()は、それと関数内のパスのみを受け入れますcss():

$this->load->library('carabiner');
$this->carabiner->js('some/file/in/script/dir');
$this->carabiner->css('some/file/in/style/dir');
$this->carabiner->display();

return フラグを設定していくつかのスクリプトとスタイルを返し、次の$this->load->view()ような関数で Carabiner に渡すことを検討していjs_string()ます...

$custom_js = $this->load->view("js_with_php_in_it", null, true);
$this->carabiner->js_string($custom_js);

from_string($type, $str)最初のパラメーターとして「js」または「css」のいずれかを取り、2 番目のパラメーターとして文字列自体を取るCarabiner メソッドを作成することで、実際には複雑な方法で問題を解決しました。

function from_string($type, $str){
    //we'll name the file using this.
    $uniq = uniqid();
    //create a temporary file in the system's /tmp directory.
    $tmpAsset = tempnam("/tmp", $uniq);
    //Carabiner requires that your scripts are relative to $config['script_dir']
    //create a symbolic link in this directory because you can't pass it absolutes.
    $this->symbolicAsset = "assets/{$type}/{$uniq}";
    //open the file named with the unique ID in /tmp and set it up for writing.
    $handle = fopen($tmpAsset, "w");
    //write the script or style to this temporary file.
    fwrite($handle, $str);
    //point the symlink at it
    symlink($tmpAsset, $this->symbolicAsset);
    //pass this directory off to $this->carabiner->css() or $this->carabiner->js()
    $this->$type($uniq);
}

次にunlink()、カラビナの一時ファイル__destruct()...しかし、明らかなオーバーヘッドの理由から、このソリューションは非常に嫌いです.カラビナの厳格なアセットディレクトリルールのためだけに、元の内容と同じ内容を含む一時ファイルを作成しています. 過去にカラビナを変更して、文字列を解析できるようにした人はいますか?

4

2 に答える 2

1

これは、このライブラリに欠けている優れた機能です。この質問を見た後、主要なプロジェクトでこのライブラリを使用しました。javascript と css スタイルを文字列またはグループを持つ文字列の配列として受け入れるようにライブラリにいくつかの変更を加えました。一時ファイルは作成されません。 create in pages script tag and styles ここでは、このライブラリがどのように機能するかを示します。

JavaScript文字列

// script passed as string
$this->carabiner->js_string('alert("test script")'); 

// script passed as array
$this->carabiner->js_string(array('alert("test script")','alert("test script")'); 

// script passed as string with group name
$this->carabiner->js_string('alert("test script")','group_name'); 

// script passed as array with group name
$this->carabiner->js_string(array('alert("test script")','alert("test script")','group_name'); 

//load javascript along with javascript files without group name
$this->carabiner->display('js');

//load javascript along with javascript files with group name
$this->carabiner->display('group_name');

css スタイル文字列

// style passed as string
$this->carabiner->css_string('p{background:red}'); 

// styles passed as array
$this->carabiner->css_string(array('p{background:red}','p{background:red}'); 

// style passed as string with group name
$this->carabiner->css_string('p{background:red}','css_group_name'); 

// style passed as array with group name
$this->carabiner->css_string(array('p{background:red}','p{background:red}','css_group_name'); 

//load style along with javascript files without group name
$this->carabiner->display('css');

//load styles along with javascript files with group name
$this->carabiner->display('css_group_name');

これが私のgitレポです。作成したばかりで、pull Git Repoのリクエストを送信しました

于 2013-02-20T08:44:20.930 に答える
0

本当に答えではありませんが、試してみてください:

_get_contents メソッドをハッキングして .php ファイル拡張子を検出し、php 拡張子呼び出しがある場合は、途中で$this->CI->load->view('asset.php', true)file_get_contents()ない可能性があると思います。私の熟読から、これはおそらく縮小または結合を使用した場合にのみ機能します。

于 2013-02-15T22:02:16.427 に答える