Question

I'm having a trouble with the response output of the Kohana Framework 3.2

Perhaps this is a known issue, but I have not been able to find a similar question or a response in the matter.

Whenever I make a request to a controller and I get a response in the form:

$this->response->body($aView->render());

I receive the response in the browser, but also, at the beginning of the response appears an undesired "<" character.

It isn't a trouble for simple requests but when i try to make an ajax request to receive a json response It breaks the code flow.

Additional info: In the views, I'm using the meta tag setting the charset as "utf-8".

Can anyone help me? Thanks in advance

p.s: sorry if it was questioned before or if it appears in the google searches. Perhaps I've used the wrong search keywords.

------------------------- More details about the question -------------------------------

To show a simple example of this behaviour I'm posting code of the controller, the view and the unexpected response that currently shows what I'm asking.

First, I have a user controller who manages users (create,update,delete) and login/logout actions. For instance, when I'm registering a new user, I have a method that receives a username, checks if exists in the database and gives back to the browser a json reply notifying the existence or not of the given username.

  <?php defined('SYSPATH') or die('No direct script access.');
  class Controller_User extends Controller {

  //additional code

  public function action_existsusername(){
      $username_candidate = $this->request->param("username",""); 

      $user = ORM::factory("user")->where("username","=",$username_candidate)->find();
      $reply = ($user->id) ? '{"reply":"true"}': '{"reply":"false"}' ;

      $this->response->body($reply);
  }

  //more code

}

But when I see the reply, the text goes as follows,

<{"reply":"false"}

I'm never appending a "<" less than character to the response. This behaviour also appears when I'm trying to get partial views from the server in html (it always prepends to the response that character).

In the above example, I've also tried to send headers (in this case application/json) but the result is pretty much the same.

Hope it clarifies for an answer, thanks for answering ;)

Was it helpful?

Solution

You probably have an additional '<' character at the beginning of one of your php files. Try searching your files for "<<?php" or "<<?".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top