Welcome Guest, Not a member yet? Register   Sign In
Using QUERY_STRING on CI4
#1

How can I make CI 4 to use URLs like this:

http://mysite.com/index.php?page=home
http://mysite.com/index.php?page=mail
http://mysite.com/index.php?page=register
http://mysite.com/admin/index.php?page=users
http://mysite.com/admin/index.php?page=permissions
http://mysite.com/admin/index.php?page=permissions&c=1&t=5

I've tried setting on app/Config/App.php the following:

PHP Code:
public $uriProtocol 'QUERY_STRING'

But I was not able to make this work. The url structure is not the same as CI 3

Before you could do something like this

http://mysite.com?c=controller&m=method&param1=x&param2=y

Is there any way to do this?
Reply
#2

My first question would be, why would you even want to do this for the controllers and all the routing?

If you only want to get a value from the query string you can use getVar() or getGet():
PHP Code:
$something $request->getVar('foo');
$something $request->getGet('foo'); 


See: https://www.codeigniter.com/user_guide/i...ving-input
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#3

(This post was last modified: 11-14-2020, 09:32 AM by captain-sensible.)

the other thing you might be missing is routes

default route is:

$routes->get('/', 'Home::index');

that means when someone goes to just domain , then what happens is defined in Controller Home and method inside Controller home called index.

You can have get and post requests eg

Code:
$routes->get('addProduct','Product::productAddForm');
$routes->post('addProduct','Product::addProductDo');

lines mean: ('url',' Controller Class::methodOfClass)

my first one means when admin goes to url domain.com/addProduct they get a form .Method productAddForm looks like

Code:
public function productAddForm()
          
          {
               $data = [
                        'title'  => 'add product ',
                        'date'=>$this->myDate,
                        'info'=>' '
                ];
                echo view('addProductForm',$data);
          }



forgot to mention this elelement of route:

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


Code:
    public function showArticle($theSlug)
                    
                    {
//to see value of $theSlug
echo $theSlug
Arch Book  CodeIgniter4 on Apache(pages 92-114) 
Reply
#4

(11-14-2020, 05:31 AM)includebeer Wrote: My first question would be, why would you even want to do this for the controllers and all the routing?

If you only want to get a value from the query string you can use getVar() or getGet():
PHP Code:
$something $request->getVar('foo');
$something $request->getGet('foo'); 


See: https://www.codeigniter.com/user_guide/i...ving-input

I know it's not the most convenient thing, but I'm migrating an application and I need to change a lot of URLs. Being able to keep the current routing is the best option for me
Reply
#5

(11-14-2020, 07:22 AM)lucky Wrote: I know it's not the most convenient thing, but I'm migrating an application and I need to change a lot of URLs. Being able to keep the current routing is the best option for me

What are you migrating from? An old version of CI of something else?

I never used this feature before and I'm not sure if it's still available in CI4.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#6

(11-14-2020, 10:07 AM)includebeer Wrote:
(11-14-2020, 07:22 AM)lucky Wrote: I know it's not the most convenient thing, but I'm migrating an application and I need to change a lot of URLs. Being able to keep the current routing is the best option for me

What are you migrating from? An old version of CI of something else?

I never used this feature before and I'm not sure if it's still available in CI4.

The application is not based on CI3. It's a custom framework. So I was trying to avoid migrating something else.
Reply
#7

PHP Code:
$uri    $request->uri;
$result $uri->getQuery(); 

Will give you it all.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB