Welcome Guest, Not a member yet? Register   Sign In
Require_once in all controller, but not in all...
#1

[eluser]daweb[/eluser]
Hi guys.

My problem today is:

I have to include this code:

require('E:/SHARED/DAWEB/progettiweb/myproject/php_speedy/php_speedy.php');

[MY PAGES]

$compressor->finish();

at the very top and very bottom of all my pages to compress css and js files.
I think to put the two lines in index.php, but there's a problem when there is an ajax call.

And if your script is redirecting to another location (Ajax) then there’s nothing to compress, so don’t add the PHP Speedy code to that page.

So, I have to put the two lines of code in all my controllers, not in ones that returns an Ajax call... Some ideas to do that? I think is not the best way write the lines in all my controllers...

Thank you, sorry for english.
#2

[eluser]tonanbarbarian[/eluser]
why not try something like this
add the following code to your controllers
Code:
function _output($output) {
    if (!$this->_ajax) {
        require(’E:/SHARED/DAWEB/progettiweb/myproject/php_speedy/php_speedy.php’);
        echo $output;
        $compressor->finish();
    } else {
        echo $output;
    }
}
This will use your compression code if the _ajax property of the controller is false
So then you just need to declare the variable in the controller
Code:
class XXX extends Controller {

    var $_ajax = false;

    function xxx() {
    }
    ...
}
and then if the method in the controller will be returning ajax set the property to true
Code:
$this->_ajax = true;
much neater and you do not have to put the code in multiple times




Theme © iAndrew 2016 - Forum software by © MyBB