开发者

Carabiner question -- Codeigniter library

When I use the carabiner library,开发者_StackOverflow中文版 my css and js files are appended to the top of the page. Is there a way i could specify where the files should be appended maybe try to send the files as an array to my view files?

thanks


May differ slightly based on how you are rending your views, but with the conventional, lackluster way of doing it, here's an example:

Home controller:

public function index()
{
  $this->carabiner->css('default.css')
  $this->carabiner->js('custom.js');
  $data['assets'] = $this->carabiner->display_string('both');

  $this->load->view('templates/header', $data);
  $this->load->view('home/index', $data);
  $this->load->view('templates/footer');
}

Header view:

<html>
<head>
<title>Title of Page</title>
<?php echo $assets; ?>
</head>
...


This was one of my major annoyances with Carabiner, unbuffered output. Every output function echos the return value instead of.. returning it.

Without hacking up the library (which I would personally do), here is an example of how to do what your'e asking:

ob_start();
$this->carabiner->display('css');
$css = ob_get_clean();

Now you have a variable with the js/css tag output you can send to your view file or template. Without the output buffering, this would print the tags to your output immediately. Note that if you want, another workaround is to make sure you don't call the output functions until you need them, like in the template itself.

If you wanted to fix this permanently, go through the Carabiner library and replace every instance of echo $some_return_value; to return $some_return_value; (last line of any output function). There are a lot, so this will take a little time.

As far as returning arrays, I'm not too sure - I never made it that far with Carabiner (didn't like it). Hopefully this helps all the same. Good Luck!

Read more on output buffering: http://php.net/manual/en/book.outcontrol.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜