Welcome Guest, Not a member yet? Register   Sign In
CI4- how to pass string with slash(/) to controller
#1

i need to pass data that contain slash(/) to ci4 controller.

in ci3 there is no problem
Reply
#2

How do you do in CI3?
Reply
#3

(02-13-2023, 04:11 PM)kenjis Wrote: How do you do in CI3?

in ci3 : first i need change permited uri config

Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_()@&\-!';


thats all

passing data contains slash (/) work
view 
PHP Code:
"<?php echo site_url('Iobrg/downloadSMB/056/SMB-PAP/XII/2022') ?>

controller :  
public function downloadSMB($nomor_smb1)
dd($nomor_smb1) }


output 
string 
056/SMB-PAP/XII/2022


in CI4 
Output only 
056 
Reply
#4

In C4, you can't get parameter including /.

Code:
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -31,6 +31,8 @@ $routes->set404Override();
// route since we don't have to scan directories.
$routes->get('/', 'Home::index');

+$routes->get('iobrg/download/(:any)', 'Home::index/$1');
+
/*
  * --------------------------------------------------------------------
  * Additional Routing

Code:
--- a/app/Controllers/Home.php
+++ b/app/Controllers/Home.php
@@ -4,8 +4,8 @@ namespace App\Controllers;

class Home extends BaseController
{
-    public function index()
+    public function index(...$p)
    {
-        return view('welcome_message');
+        dd(implode('/', $p));
    }
}

http://localhost:8080/iobrg/download/056...P/XII/2022

You will see "056/SMB-PAP/XII/2022".
Reply
#5

(02-14-2023, 05:39 PM)kenjis Wrote: In C4, you can't get parameter including /.

Code:
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -31,6 +31,8 @@ $routes->set404Override();
// route since we don't have to scan directories.
$routes->get('/', 'Home::index');

+$routes->get('iobrg/download/(:any)', 'Home::index/$1');
+
/*
  * --------------------------------------------------------------------
  * Additional Routing

Code:
--- a/app/Controllers/Home.php
+++ b/app/Controllers/Home.php
@@ -4,8 +4,8 @@ namespace App\Controllers;

class Home extends BaseController
{
-    public function index()
+    public function index(...$p)
    {
-        return view('welcome_message');
+        dd(implode('/', $p));
    }
}

http://localhost:8080/iobrg/download/056...P/XII/2022

You will see "056/SMB-PAP/XII/2022".
did'nt work

[Image: Screenshot-2023-02-15-080358.jpg]
Reply
#6

PHP Code:
public function downloadSMB($nomor_smb1)

public function downloadSMB(...$nomor_smb1
Reply
#7

(02-14-2023, 06:15 PM)kenjis Wrote:
PHP Code:
public function downloadSMB($nomor_smb1)

public function downloadSMB(...$nomor_smb1

i'm sorry, i miss three dots there.

thank you very much buddy, it's work. Heart
Reply




Theme © iAndrew 2016 - Forum software by © MyBB