Welcome Guest, Not a member yet? Register   Sign In
Routing with variables
#1

Hi,

Below is my routing but I can't get the last uri segment in to the function.

PHP Code:
$routes->get('/admin/reports/stores/:num''Admin/Reports/Brands::stores/$1',['filter'=>'accessfilter']); 

here is the function

PHP Code:
public function stores($id false){
    echo $id;


not sure what I'm doing wrong here  Sad
Reply
#2

(This post was last modified: 11-18-2021, 01:28 AM by captain-sensible. Edit Reason: characters without [code] giving me an emjoi )

try with '/admin/reports/stores/(:num)'




whats your class structure ?

For a Class Admin which has a method stores it would just be :
Code:
'Admin::stores/$1'
CMS CI4     I use Arch Linux by the way 

Reply
#3

I'd should not be false as default since you are expecting an id in this controller.
Reply
#4

true well spotted
CMS CI4     I use Arch Linux by the way 

Reply
#5

(This post was last modified: 11-18-2021, 02:05 AM by chakycool.)

Thanks guys for the response.

this '/admin/reports/stores/(:num)' did not work Sad

this the path to the controller "Admin/Reports/", the controller is "Brands" and the function is "stores" hence
PHP Code:
"Admin/Reports/Brands::stores/$1" 
.

this works "/admin/reports/stores/:num' but the value ":num" can not be picked up by the function "stores"

I'm on CI-4.14
Reply
#6

(This post was last modified: 11-18-2021, 02:38 AM by captain-sensible.)

i would like you to try domain.something/admin/reports/stores/6 for web browser address bar at top url but make the route
Code:
$routes->get('admin/reports/stores/:num', 'Brands::stores/$1');
forget about the filter for now

and take out default value in method for now

i've taken out the forward slash in front of admin as well
CMS CI4     I use Arch Linux by the way 

Reply
#7

Yes the default routing works Big Grin

Any idea how to manage custom routing and have the auto routing off?

PHP Code:
$routes->setAutoRoute(false); 
Reply
#8

$routes->setAutoRoute(false); looks like you just did it !


section on mine is:

Code:
/**
* --------------------------------------------------------------------
* Router Setup
* --------------------------------------------------------------------
*/
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(false);


this is a sample of my routes in Routes.php

Code:
$routes->get('setUp','Setup::setUpForm');
$routes->post('setUpDo','Setup::process');
$routes->get('/', 'Home::index');
$routes->get('addProduct','Product::productAddForm');
$routes->post('addProduct','Product::addProductDo');

play around and yo uwill be fine ; make sure you have version control , i.e git i like "tags" to go back to incase their is a problem
CMS CI4     I use Arch Linux by the way 

Reply
#9

(This post was last modified: 11-18-2021, 03:37 AM by chakycool.)

with the auto route off we can't pass these variable on the URI unless the URI class is used. So, any idea how can we have a custom routs with data been passed as my code below (which is not working)

PHP Code:
$routes->get('/admin/reports/stores/:num''Admin/Reports/Brands::stores/$1'); 
Reply
#10

(This post was last modified: 11-24-2021, 02:23 AM by InsiteFX. Edit Reason: forward slashes should be back slashes on namesapce )

Try this your missing the () on :num.

PHP Code:
$routes->get('/admin/reports/stores/:num''Admin/Reports/Brands::stores/$1'); 

// should be
$routes->get('/admin/reports/stores/(:num)''Admin\Reports\Brands::stores/$1'); 

Let me know if that works for you.

EDITED: according to @iRedds
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