Welcome Guest, Not a member yet? Register   Sign In
Array Callable route
#1

(This post was last modified: 07-15-2022, 05:53 AM by luckmoshy.)

whats up gentle Guys, I just have a silly query here,

PHP Code:
$routes->match(['post','get'],'/', [\App\Controllers\Gearbox\ChangeGearController::class, 'insertGearMethod']);/*['as'=>'changegear']*/ 

I want to name-route this route How do I do? have tried but getting errors. Thanks
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#2

What errors?
Reply
#3

(This post was last modified: 07-16-2022, 12:31 AM by luckmoshy.)

(07-15-2022, 08:23 AM)iRedds Wrote: What errors?

Sorry for the late reply @iRedds yes! I face 
PHP Code:
//(This woks fine but for array how to do?) 
//$routes->match(['get','post'],'login', 'AuthController::login',['as'=>'login']); 

PHP Code:
explode(): Argument #2 ($string) must be of type string, array given 

I use this assoc array way so what is the best way to do this route as a named route?

PHP Code:
<?=base_url(route_to('login'))?>
PHP Code:
$routes->match(['get','post'],'login', [AuthController::class, 'login','as'=>'login']); 
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#4

Please Read:

CodeIgniter 4 User Guide - URI Routing - Using Named Routes
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

@luckmoshy Options must be specified separately.

$routes->match(['get','post'],'login', [AuthController::class, 'login'], ['as'=>'login']);
Reply
#6

(This post was last modified: 07-16-2022, 01:02 AM by luckmoshy.)

(07-16-2022, 12:33 AM)InsiteFX Wrote: Please Read:

CodeIgniter 4 User Guide - URI Routing - Using Named Routes

Thank @InsiteFX for your quickly reply because I know the named route as you've directed me to view the deep query I want to know for new CI 4.2 array callable route as named route
PHP Code:
$routes->match(['get''post'], 'login', [AuthController::class, 'login']); 
how to do it by named route action?

(07-16-2022, 12:48 AM)iRedds Wrote: @luckmoshy Options must be specified separately.

$routes->match(['get','post'],'login', [AuthController::class, 'login'], ['as'=>'login']);

Thank you now have got you clear
Code:
(Options must be specified separately)
Thank you

Thank you @iRedds for your great time this is what exactly I wanted so the problem solved 100% in this way

PHP Code:
$routes->match(['get','post'],'login', [AuthController::class, 'login'], ['as'=>'login']); 
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#7

I didn't know we can set the same route name to different (HTTP verb) routes.
Reply
#8

Try this:

PHP Code:
$routes->match(['get''post'], 'login''AuthController::class', ['as' => 'login']); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#9

(This post was last modified: 07-17-2022, 05:34 AM by luckmoshy.)

(07-16-2022, 11:34 PM)InsiteFX Wrote: Try this:

PHP Code:
$routes->match(['get''post'], 'login''AuthController::class', ['as' => 'login']); 

Thanks, @InsiteFX This issue was solved

PHP Code:
$routes->match(['get','post'],'login', [AuthController::class, 'login'], ['as'=>'login']); 
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply




Theme © iAndrew 2016 - Forum software by © MyBB