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