How to prevent Zend Framework 1 from resolving a controller name with a dot at the end?

I have a website that runs on Zend Framework 1.12. It has a controller named "users". When I enter its name incorrectly - http://mywebsite/userss - I rightfully receive an error message saying that such a controller does not exist. However, when I add a period to the end of her name, http://mywebsite/users. , the error indicates that the viewcript named users./index.phtml does not exist. Interestingly, it still gets the controller (users) correctly.

I have two questions on this:

  • How and why does it ignore the dot at the end and still correctly receive the controller?
  • Is there a way to reject controller names without any changes to the core structure?
+4
source share
1 answer

Great question, but to answer that, we dug up the Zend Framework source code and initially returned by 2007, the _formatName() function was specifically designed to remove such anomalies from the URL name. Maybe it was before that, but I don’t know that.

This particular snippet is from Zend Framework 0.1.4 (Historic Right?) :)

 protected function _formatName($unformatted) { $unformatted = str_replace(array('-', '_', '.'), ' ', strtolower($unformatted)); $unformatted = preg_replace('[^a-z0-9 ]', '', $unformatted); return str_replace(' ', '', ucwords($unformatted)); } 

Here you see - , _ and . in the first step.

Even today, this feature is set to uninstall - and . but not _

Here is the current version of Zend Framework 1.x of this feature

 protected function _formatName($unformatted, $isAction = false) { // preserve directories if (!$isAction) { $segments = explode($this->getPathDelimiter(), $unformatted); } else { $segments = (array) $unformatted; } foreach ($segments as $key => $segment) { $segment = str_replace($this->getWordDelimiter(), ' ', strtolower($segment)); $segment = preg_replace('/[^a-z0-9 ]/', '', $segment); $segments[$key] = str_replace(' ', '', ucwords($segment)); } return implode('_', $segments); } 

As before the URI segment is cleared on this line

 $segment = str_replace($this->getWordDelimiter(), ' ', strtolower($segment)); 

The getWordDelimeter() function returns an array('-', '.'); [line] thereby deleting them primarily in the URL that answers your first question . About the second question, you can change this line and remove from it . .

 protected $_wordDelimiter = array('-', '.'); 

After this, Despatcher will no longer find the controller or any component of the URI with . On him.

+1
source

Source: https://habr.com/ru/post/1492331/


All Articles