Welcome Guest, Not a member yet? Register   Sign In
Use different 404 page on front-end and back-end
#1

Hi I'd like to ask a question please. I'm building a project in which I'm having this folder structure:

Code:
application
- controllers
-- posts.php // this is on frontend
-- admin
--- posts.php // this is on backend obviously

So in both cases if I try to access from the url a post that doesn't exist I'll do something like this

PHP Code:
$data['post'] = $this->post_model->get_by_id($id);
// Return 404 if post not found
if (count($data['post']) > 0) {
      
// do something ...
} else {
    
show_404();


which shows the default 404 Codeigniter page.

Is it possible to set a different 404 page for front end and back end and if so how can I do this ?

The only options I have thought so far are these:

1st. Have the same custom 404 page for both front end and back end, in which case I only have to set a different 404 view to the default file, but I don't think its the best option.

2nd (not tested). Create 2 different controllers and views, like this
PHP Code:
applicatiom
controllers
-- front404.php
-- admin
--- admin404.php 

so when I check if the post exist, it would become like this

PHP Code:
if (count($data['post']) > 0) {
      
// do something ...
} else {
        
// redirect to front 404 or admin 404 depend on whether I'm on public site or on the admin area
    
redirect('admin/admin404'); // so on front end it would be redirect('admin/front404'); instead


3rd (also not test). A similar to 2nd option, but setting the $route['404_override'] = ''; dynamically. Would that be possible ??

However I was wondering if there's a more efficient way of doing this. Btw I'm using CodeIgniter v3.
Reply


Messages In This Thread
Use different 404 page on front-end and back-end - by Lykos22 - 09-28-2015, 03:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB