Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1060713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:22:07+00:00 2026-05-16T18:22:07+00:00

I use redirect() (from uri helper) in every function who need to load the

  • 0

I use redirect() (from uri helper) in every function who need to load the main view of my app. It redirect to the same function. My goal is to get the same clean uri, even when i use a pages’ feature (that call other controller). Is it good practice? When should i use redirect()? Are there any other solution to get a similar result?

this is some code to clarify.

Here is a controller :

<?php

   class Main_controller extends Controller
   {
       function index()
       {
       $this->load->view(page); 
       }

       function page_feature()
       {
       /* some stuff */
       redirect('main_controller.php','refresh');
       }
   }

With this route rules :

$route['([a-z-A-Z1-9_]+)'] = "main_controller";

The uri is like this : myapp.com/something
On this page, there are feature who calls (on submit) other functions of main_controller ( or other controller), like a form for example:

<form action="myapp.com/another_controller/method" method="post">

at the end of this query “/another_controller/method”, i use redirect(‘main_controller’) to display the view with the new data, and keep the uri “myapp.com/something” instead of “myapp.com/another_controller/method”.

I wanted to know if this is good or bad practice, and why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:22:07+00:00Added an answer on May 16, 2026 at 6:22 pm

    It’s bad practice to use redirects like that; you’re basically doubling the # of server requests.

    If you don’t want to have the function names in the URL, just have the form POST to the controller index() function, and call the function you need based on some criteria such as what was passed from the forms POST data:

    <form action="myapp.com/controller_name" method="post">
    

    Controller:

    function index(){
            if(!empty($_POST['some_form_data'])){
                $this->page_feature(); 
           }
           else{
                $this->load->view('page');
            }
    }
    function page_feature(){
           /* some stuff */
           $this->load->view('page_feature');
    }
    

    You may also want to check out the _remap() function. That way additional uri segments are not treated as function calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need my Android application to run a certain Activity in my app, responding
I want to redirect from a link in a JSF page, how can I
I would like to use with on an object that uses __getattr__ to redirect
I've set up a Rails 3 proxy method inside a controller to use Nginx'
I've got two hostnames (e.g. www.site1.com and www.site2.com) mapped to the same apache virtual
I'm about to update my site to use CakePHP instead of an old homegrown
I have a lot of images on my website, they are pulled from an
From a Rails controller, is there a way to determine if the request was
I want to redirect the die messages to a separate file so that I
I have html static files on my server. I want the access rules as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.