Tabs are displayed using cakephp?

I developed a web application with cakephp locally on Windows XP using xampp and everything works fine. Today I deployed it to CentOS and Ubuntu Server, and I had a problem. What happens is that the tab space is displayed along with my information. Let's say I make an ajax call that should return OK , what is returned is " OK" , more precisely (0x09)OK

I do not know where this tab comes from. I have reduced my code to the maximum, and still get it.

controller

 public function sendcomment() { $this->layout = 'ajax'; $this->set('ret', 'OK'); } 

View

 <?php echo $ret; ?> 

Even if I do not use the view file and the exit information directly on the layout, the tab still exists:

controller

 public function sendcomment() { $this->layout = 'testlayout'; } 

testlayout.ctp

 OK 

This happens in all actions, regardless of what a layout is.

Did anyone go through this and find out what could happen? All my files are encoded in UTF-8 without specification, and they work fine with XAMPP on Windows.

- Change:

Ok, some said it was a config problem, I really don't know. However, trying to find where the tab came from, I started placing echoes in the main files and moving on and on until I finally get to where the tab is. Regarding index.php from the cake web peel, if I put echo 'a' before the dispatch() method, my result is a(0x09)OK . So the tab really comes from the cake.

Now here is the problem, looking at the results of several tests, I finally got stuck, and this did not lead to anything.

Now I am on (CakeRoot)/lib/Cake/Routing/Dispatcher.php . Here we have the following method:

 protected function _loadController($request) { $pluginName = $pluginPath = $controller = null; if (!empty($request->params['plugin'])) { $pluginName = $controller = Inflector::camelize($request->params['plugin']); $pluginPath = $pluginName . '.'; } if (!empty($request->params['controller'])) { $controller = Inflector::camelize($request->params['controller']); } if ($pluginPath . $controller) { $class = $controller . 'Controller'; App::uses('AppController', 'Controller'); App::uses($pluginName . 'AppController', $pluginPath . 'Controller'); App::uses($class, $pluginPath . 'Controller'); if (class_exists($class)) { return $class; } } return false; } 

I am exactly in this part:

  App::uses($class, $pluginPath . 'Controller'); if (class_exists($class)) { return $class; } 

Now here are the tests if I put echo right before the if, for example:

  App::uses($class, $pluginPath . 'Controller'); echo 'a'; if (class_exists($class)) { return $class; } 

My output will be a(0x09)OK . However, if I put my echo right inside, if so:

  App::uses($class, $pluginPath . 'Controller'); if (class_exists($class)) { echo 'a'; return $class; } 

My output will be (0x09)aOK . The only thing that comes to my mind is that class_exists() performs an echo tab. But that just doesn't make any sense. For testing purposes, I did the following:

  App::uses($class, $pluginPath . 'Controller'); if (TRUE) { return $class; } 

Still, the tab is displayed. Even worse, if I do if == TRUE like this, regardless of whether the echo is “a” before if or to the right inside the if, the output will always be a(0x09)OK .

What the hell is going on here?

+8
php cakephp
source share
1 answer

So the tab really comes from the cake.

This is the wrong conclusion.

You almost have

To paraphrase your code:

 App::uses($class, $pluginPath . 'Controller'); echo "before"; if (class_exists($class)) { echo 'after'; return $class; } 

Outputs: before(0x09)after

There is no great secret. The class_exists used in this way will autoload classes - that is, include them and any immediate class dependencies (since they will also start loading the class). Therefore, there is a very short list of places from which it can come:

  • Controller / $class Controller.php
  • Plugin / Foo / Controller / FooAppController.php (if it is a plugin controller)
  • Controller /AppController.php (if it exists)

One of these files has leading or trailing spaces - just find it and delete it.

Use the tools at your disposal

You do not need to guess which file is the problem; there are many, many tools that will tell you which file is the culprit. One of these tools is in the debug set module, for example:

 -> Console/cake DebugKit.whitespace Welcome to CakePHP v2.3.0-RC2 Console --------------------------------------------------------------- App : app Path: /path/to/app/ --------------------------------------------------------------- Checking *.php in /path/to/app/ !!!contains trailing whitespaces: /app/Controller/AppController.php 
+1
source share

All Articles