Welcome Guest, Not a member yet? Register   Sign In
Injecting view name into output
#1

[eluser]bgammill[/eluser]
Hi everyone. I'm working on a site with a massive code base, with something like a hundred view files (header.php, footer.php, etc). As I'm developing and debugging I'm finding it hard to find what chunk of JavaScript code is in what view. I'm looking for a plugin that would inject the name of each view into the final output. It would look something like this...

Code:
<!-- BEGIN header.php -->
<head>
    <title>Weight Loss Extravaganza</title>
</head>
<!-- END header.php -->

<!-- BEGIN navigation.php -->
<ul>
    <li>home</li>
    <li>contact us</li>
</ul>
&lt;!-- END navigation.php --&gt;

I searched pretty heavily for a solution, but couldn't find anything obviously. I appreciate your time. Thanks!
#2

[eluser]boltsabre[/eluser]
Forgive me if I've missed something here, but why can't you just go and put &lt;!-- BEGIN header.php --&gt; at the start of header.php, &lt;!-- END header.php --&gt; at the end of it, the same for navigation and so on?

Or are you saying that each page is made of 100 view files?

To the best of my knowledge there isn't anything out there that would do this for you, I think you'll have to do it yourself. Look on the bright side, 100 views, 30 seconds to put the comments in each view = 50 minutes worth of work, not too bad.
#3

[eluser]bgammill[/eluser]
[quote author="boltsabre" date="1369847660"]Forgive me if I've missed something here, but why can't you just go and put &lt;!-- BEGIN header.php --&gt; at the start of header.php, &lt;!-- END header.php --&gt; at the end of it, the same for navigation and so on?

Or are you saying that each page is made of 100 view files?

To the best of my knowledge there isn't anything out there that would do this for you, I think you'll have to do it yourself. Look on the bright side, 100 views, 30 seconds to put the comments in each view = 50 minutes worth of work, not too bad.[/quote]

Thanks for the reply. I guess I'll have to do it the old fashioned way.
#4

[eluser]TheFuzzy0ne[/eluser]
Maybe you could overload the loader's view() method?
#5

[eluser]bgammill[/eluser]
[quote author="TheFuzzy0ne" date="1369849584"]Maybe you could overload the loader's view() method?[/quote]
That worked perfectly. In Loader.php I echoed $_ci_file right after the output buffer starts and right before it ends. Thanks!
#6

[eluser]TheFuzzy0ne[/eluser]
It's wise to avoid editing anything in the ./system directory. Instead you should create a file in ./application/core and name it MY_Loader.php

./application/core/MY_Loader.php
Code:
&lt;?php defined('BASEPATH') OR exit('No direct script access allowed.');

class MY_Loader extends CI_Loader {

    /**
     * Load View
     *
     * This function is used to load a "view" file.  It has three parameters:
     *
     * 1. The name of the "view" file to be included.
     * 2. An associative array of data to be extracted for use in the view.
     * 3. TRUE/FALSE - whether to return the data or load it.  In
     * some cases it's advantageous to be able to return data so that
     * a developer can process it in some way.
     *
     * @access   public
     * @param    string
     * @param    array
     * @param    bool
     * @return   void
     */
    function view($view, $vars = array(), $return = FALSE)
    {
        ob_start();
        
        echo '&lt;!-- BEGIN ' . pathinfo($view, PATHINFO_FILENAME) . '.php --&gt;'.PHP_EOL;
        echo $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => TRUE)) . PHP_EOL;
        echo '&lt;!-- END ' . pathinfo($view, PATHINFO_FILENAME) . '.php --&gt;'.PHP_EOL;
        
        if  ($return === TRUE)
        {
            $buffer = ob_get_contents();
            @ob_end_clean();
            return $buffer;
        }
        
        if (ob_get_level() > $this->_ci_ob_level + 1)
        {
            ob_end_flush();
        }
        else
        {
            $_ci_CI->output->append_output(ob_get_contents());
            @ob_end_clean();
        }
    }
}

// End of file MY_Loader.php
// Location: ./application/core/MY_Loader.php

This makes it easier if you ever decide to upgrade your system files.




Theme © iAndrew 2016 - Forum software by © MyBB