Welcome Guest, Not a member yet? Register   Sign In
CI disabling views
#1

[eluser]Ngulo[/eluser]
Hello everyone.

I'd like to know how do I disable the view of an Ajax/JSON function?

I guess it is sufficient to not specify : $this->load->view('some_view');
, but I ask you to be sure guys Smile

thanks
#2

[eluser]WanWizard[/eluser]
What do you mean by "disable"? You don't want a particular URL that provides a JSON result to be accessable via the browser?
#3

[eluser]Ngulo[/eluser]
yes yes you are right what you say is what I want to come back to me
I was just thinking that went disabled the view, but if
I do not specify $ this-> load-> view () I think it is already disabled by
default
#4

[eluser]WanWizard[/eluser]
I have a helper to check for ajax calls:

Code:
/**
* is_ajax_call
*
* Determines if the current page request is done through an AJAX call
*
* @access    public
* @param    void
* @return    boolean
*/
if ( ! function_exists('is_ajax_call'))
{
    function is_ajax_call()
    {
        if ( isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == "XMLHttpRequest")
        {
            // we should do more checks here, for now this is it...
            return TRUE;
        }
        else
        {
            return FALSE;
        }
    }
}

For URL's that return JSON instead of HTML, I check in the controller method() if it's an ajax call, and if not, redirect to a 404 page.
#5

[eluser]Buso[/eluser]
Thanks for sharing :lol:
#6

[eluser]Ngulo[/eluser]
really great job Wan Wink and thanks for sharing




Theme © iAndrew 2016 - Forum software by © MyBB