Welcome Guest, Not a member yet? Register   Sign In
Routes problem
#1

Hi,

I have those routes defined:

Code:
$routes->add('registracija', 'Pers/Registracija::index');
$routes->add('registracijaPotvrdi', 'Pers/Registracija::registracijaPotvrdi');
$routes->add('korisnik', 'Pers/UserPocetna::index');
$routes->add('korisnik/mojsadrzaj', 'Pers/UserPocetna::index');
$routes->add('korisnik/profil', 'Pers/UserProfil::index');
$routes->add('korisnik/odjava', 'Pers/Login::logOut');
$routes->add('korisnik/prijava', 'Pers/Login::index');
$routes->add('korisnik/login', 'Pers/Login::index');
$routes->add('korisnik/loginPotvrdi', 'Pers/Login::loginSubmit');
$routes->add('korisnik/promjenaPodataka', 'Pers/UserProfil::promjenaPodatakaPotvrdi');
$routes->add('korisnik/admin/noviFeed_Obrada', 'Pers/UserAdministracija::noviFeed_Obrada');
$routes->add('korisnik/admin/noviFeed', 'Pers/UserAdministracija::noviFeed');
$routes->add('korisnik/admin', 'Pers/UserAdministracija::index');

now I want to add this 
Code:
$routes->add('korisnik/admin/urediFeed/(:num)', 'Pers/UserAdministracija::urediFeed/$1');

but when I add it, I always get 404 - File Not Found with some controller that I even don't have. If you remove (:num)  (and remove argument from method) it works so it is 100% something with routes and not with method and controller.
Reply
#2

Please show the exact 404 message including "some controller that I don't have."

Just a guess, but I suspect you have not used namespace correctly.
Reply
#3

(This post was last modified: 06-14-2020, 10:15 AM by Didytz.)

(06-14-2020, 08:41 AM)dave friend Wrote: Please show the exact 404 message including "some controller that I don't have."

Just a guess, but I suspect you have not used namespace correctly.
So if i try to access that route with:
korisnik/admin/urediFeed/22
I get this:
Quote:Controller or its method is not found: \App\Controllers\Pers::index


It should not be namespace, because when I remove (:num) and $1, that route opens file from view which should be opened before  with (:num) and $1 in route definition.

EDIT:

I decided to test this route with this:
I added (:num) in URI part and removede $1 from "right side" parameter, and it worked. But as soon as I add .... 'Pers/UserAdministracija::urediFeed/$1', it stop working. So am I passing $1 in correct way to my method "urediFeed" or what?
Reply
#4

Just out of curiosity, what happens if you change (:num) to (:any), and move the new route between the lines:

Code:
$routes->add('korisnik/promjenaPodataka', 'Pers/UserProfil::promjenaPodatakaPotvrdi');
$routes->add('korisnik/admin/urediFeed/(:any)', 'Pers/UserAdministracija::urediFeed/$1');
$routes->add('korisnik/admin/noviFeed_Obrada', 'Pers/UserAdministracija::noviFeed_Obrada');
Reply
#5

(06-14-2020, 11:46 AM)burgoyn1 Wrote: Just out of curiosity, what happens if you change (:num) to (:any), and move the new route between the lines:

Code:
$routes->add('korisnik/promjenaPodataka', 'Pers/UserProfil::promjenaPodatakaPotvrdi');
$routes->add('korisnik/admin/urediFeed/(:any)', 'Pers/UserAdministracija::urediFeed/$1');
$routes->add('korisnik/admin/noviFeed_Obrada', 'Pers/UserAdministracija::noviFeed_Obrada');


Same thing  Blush

I did found solution but it didn't resolve actual problem... Instead of passing $1 to method urediFeed, now that method is not accepting any value but inside of it I decode URI segments and take 4th...
Reply
#6

PHP Code:
// Change to the below
$routes->add('korisnik/admin/urediFeed/(:any)''Pers/UserAdministracija::urediFeed/$1');

// Try this
$routes->get('korisnik/admin/urediFeed/(:any)''Pers/UserAdministracija::urediFeed/$1'); 
What did you Try? What did you Get? What did you Expect?

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

(06-15-2020, 02:55 AM)InsiteFX Wrote:
PHP Code:
// Change to the below
$routes->add('korisnik/admin/urediFeed/(:any)''Pers/UserAdministracija::urediFeed/$1');

// Try this
$routes->get('korisnik/admin/urediFeed/(:any)''Pers/UserAdministracija::urediFeed/$1'); 
 Tnx, will try later and report.
Reply
#8

(06-15-2020, 02:55 AM)InsiteFX Wrote:
PHP Code:
// Change to the below
$routes->add('korisnik/admin/urediFeed/(:any)''Pers/UserAdministracija::urediFeed/$1');

// Try this
$routes->get('korisnik/admin/urediFeed/(:any)''Pers/UserAdministracija::urediFeed/$1'); 

I tried with get but no luck...
Reply
#9

This is wrong:

PHP Code:
$routes->add('korisnik/admin/urediFeed/(:any)''Pers/UserAdministracija::urediFeed/$1'); 

Should be:

PHP Code:
$routes->add('korisnik/admin/urediFeed/(:any)''Pers\UserAdministracija::urediFeed/$1'); 

Namespaces use a back slash not a forward slash.
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