Welcome Guest, Not a member yet? Register   Sign In
Server Error for Wrong URL Ending
#1

(This post was last modified: 01-31-2024, 11:52 AM by mikestratton.)

A 500 internal server error is returned when the user enters the wrong URL ending. Example: https://localhost/post/10001 where 10001 is not a valid post ID. URL's with valid post ID's work as expected. Any suggestions for an easy fix?
Reply
#2

(This post was last modified: 01-31-2024, 12:43 PM by captain-sensible. Edit Reason: extra extra )

for showing blog articles i use this route:

Code:
$routes->get('blogArticle/(:segment)', 'Blog::showArticle/$1');

on a view page i foreach out a href with the following strucure
Code:
domain/blogArticle/slug-bit-of-text

each blog has in database fields Id, bulkTexArticle, slug etc

in controller I use

Code:
public function showArticle($theSlug)
                    
                    {
                      $handle = new BlogModel();
                    $result= $handle->getArticle($theSlug);
                        
                    if ($result == null)
                    {
                        
                    
                    
                    $data =[
                    'title'=>'no such blog',
                    'date'=>$this->myDate,
                    'info'=>' there is no blog with that slug in database'
                    ];
                    echo   view('info',$data);
                                
                    
                    exit();
                    
                }

model bit is

Code:
public function getArticle($slug)

    {
     return $this->asArray()
                 ->where(['slug' => $slug])
                 ->first();

    }
So basically in he URl
Code:
domain/blogArticle/slug-bit-of-text

the slug-bit-of-text is checked to see if it exists , if it doesn't view is retured saying no such blog. In yours assuming 10001 is in your databse just see if there is such an entry if not return a view no such post.




eg live this is a real blog article (daughter site)

Code:
https://andrinadesignstudio.com/blogArticle/Ghana-Adinkra-symbols

try editing Ghana-Adinkra-symbols to something else in above url and see what happens
CMS CI4 A CMS system, runs out of the box written on top of CI4
Arch Book  CodeIgniter4 on Apache(pages 92-114) 
Github  
Reply
#3

See logs, and know the cause.
https://codeigniter4.github.io/CodeIgnit...error-logs
Reply




Theme © iAndrew 2016 - Forum software by © MyBB