404 Override Not Working |
(06-20-2017, 02:03 AM)wolfgang1983 Wrote:(06-20-2017, 02:00 AM)Martin7483 Wrote: Viewing the Core code, setting a custom 404_override in ./config/routes.php does not change how the show_404() method is used. You can easily test this. Open ./system/core/CodeIgniter.php Go to line 447 if($e404) Place a die after the opening { Navigate to a thread that can not be found via your Viewthread Controller If it dies, then the required Controller could not be located. Else it was located and you need something other than show_404
(06-20-2017, 02:05 AM)reactionstudio Wrote: If you create the file: application/core/MY_Exceptions.php with the following code what happens? Thanks that works also.
There's only one rule - please don't tell anyone to go and read the manual. Sometimes the manual just SUCKS!
(06-20-2017, 02:12 AM)wolfgang1983 Wrote:(06-20-2017, 02:05 AM)reactionstudio Wrote: If you create the file: application/core/MY_Exceptions.php with the following code what happens? This will work, but you are both missing the fact that the 404_override and show_404 are not directly related. Setting the one does not change the workings of the other. IMHO changing the show_404 to fix something that is not broken because of a lack of knowledge is not the way to do things. Instead create a show_notfound() method that will handle the redirect to your custom Controller. This way you can keep using the show_404 as is, also within your custom Controller without causing an infinite redirect loop.
Martin7483 Wrote:What you need todo is create your own show_404 method or redirect to your custom Notfound controller instead of calling show_404 and pass along any needed arguments Is this not what extending the core CI_Exceptions class is achieving? ok it's not a separate function, it's extending the core instead to get the same end result but i don't see how this is a bad solution just because it's not the one you would personally go with? Please can you explain to me why it's a bad / incorrect solution?
(06-20-2017, 02:37 AM)reactionstudio Wrote:Martin7483 Wrote:What you need todo is create your own show_404 method or redirect to your custom Notfound controller instead of calling show_404 and pass along any needed arguments First: I already did Quote:This way you can keep using the show_404 as is, also within your custom Controller without causing an infinite redirect loop. If the need should arise to call the show_404() method from within the custom Notfound Controller that would cause an infinite redirect loop. Meaning if he would need to call it he would have to again build something to overcome that issue. Also any 404 unrelated to the forum he is building, will not be routed to the custom notfound controller Second: Also already mentioned You are “fixing something” that is not broken. How is that a correct approach to anything?
Martin7483 Wrote:If the need should arise to call the show_404() method from within the custom Notfound Controller that would cause an infinite redirect loop. Meaning if he would need to call it he would have to again build something to overcome that issue. This would be true if they did need to call the show_404() method within the Notfound Controller, which isn't a custom controller, they're extending the standard CI_Controller. From what they posted it does not seem like they would need to do this though as they were trying to set one controller for all 404 pages via $route['404_override'] = 'notfound'; which would suggest they only needed one 404 page, if they did then it's a different problem and a different solution is needed. Martin7483 Wrote:Also any 404 unrelated to the forum he is building, will not be routed to the custom notfound controller What if they only need one 404 page for their application? They didn't specify they needed a specific 404 page for their forum and a different one for other parts of their application, if this was needed though they could make use of the $page argument and redirect to the desired 404 page with a small modification to the code if it was required, again different problem, different solution. Martin7483 Wrote:You are “fixing something” that is not broken. How is that a correct approach to anything? I don't see how this is "fixing something that is not broken", it's changing how something works so it suits your specific needs.
Wolfgang1983 assumed that setting the 404_override would effect the way show_404 is executed by CI. I have pointed out that this is not the case as the two are unrelated. Just take a look at CodeIgniter.php starting at line 447. Setting the 404_override only causes CI to load the custom 404 Controller instead of calling the show_404 method.
Quote:What if they only need one 404 page for their application?Even if this is true, again, you are changing code to do something which can easily be done by creating a method specifically designed for the situation. I like to think ahead when coding. So say, for now only one 404 page is needed. But in the future you do need one for the forum and one for any other part of the website. You would then need to undo the solution you have provided, and build a separate method as I have suggested. Or as you point out, do something based on the passed in page argument. But then you he would need to pass in the correct page argument to execute the correct 404. Quote:I don't see how this is "fixing something that is not broken", it's changing how something works so it suits your specific needs. Changing how something works indeed is not fixing something that is broken. But changing something based on a wrong interpretation of the Core code is not the correct approach. PS. When I said custom Controller, I'm was talking about the custom 404 Controller |
Welcome Guest, Not a member yet? Register Sign In |