CodeIgniter Forums
another routing problem :) please help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: another routing problem :) please help (/showthread.php?tid=81282)



another routing problem :) please help - Kordianz - 02-12-2022

Hi,
PHP Code:
  
I create Blog, and in Blog Controller I hane method index, who select all posts and method 'wpis':

 public function wpis($id)
    {
      $dzis = Time::today('Europe/Warsaw', 'pl_PL');
      $data['menu']=1; 
      $modelw = new Blog_m();
       
      if(isset($id))
          {
            $data['id']=$id;
          }
          else
          {
            return redirect()->to('blog');
          }

etc...
And in Routing I put:
PHP Code:
$routes->get('''FRONT/Page::index');
$routes->get('/''FRONT/Page::index');
$routes->get('blog''FRONT/Blog::index'); - work
$routes
->get('wpis/(:num)''FRONT/Blog::wpis/$1'); - -this not works :(
"

Controller or its method is not found: \App::index
"

but, if I remove $
PHP Code:
$routes->get('wpis/(:num)''FRONT/Blog::wpis');

PHP Code:
Too few arguments to function App\Controllers\FRONT\Blog::wpis(), 0 passed in 

$routes->ge


RE: another routing problem :) please help - iRedds - 02-12-2022

https://forum.codeigniter.com/thread-80579-post-391775.html#pid391775


RE: another routing problem :) please help - ikesela - 02-12-2022

there is no route for /wpis , existing route is /wpis/{num}

alternatively can add this for default route:

$routes->get('wpis', 'FRONT/Blog::wpis');

change function to:

public function wpis($id = 0) // for default route


RE: another routing problem :) please help - Kordianz - 02-13-2022

(02-12-2022, 10:58 PM)iRedds Wrote: https://forum.codeigniter.com/thread-80579-post-391775.html#pid391775
Thanks, but unfortunelly:
PHP Code:
$routes->get('''FRONT\Page::index');
$routes->get('/''FRONT\Page::index');
$routes->get('blog''FRONT\Blog::index');
$routes->get('wpis/(:num)/(:segment)''FRONT\Blog::wpis/$1/$2');

And 
ofcouse add second var info function, result this same :( 404 



RE: another routing problem :) please help - InsiteFX - 02-13-2022

Namespace uses a back slash \ not a forward slash /

FRONT\Blog::wpis/$1


RE: another routing problem :) please help - Kordianz - 02-13-2022

for testin I do:
public function wpis($id=0)


and add in Routes
$routes->get('/wpis', 'FRONT\Blog:wpis');
$routes->get('/wpis/(:num)', 'FRONT\Blog::wpis/$1');

now, in url when I go in:
https://url/wpis

i get:
ErrorException
Undefined array key 1
SYSTEMPATH/Router/Router.php at line 430

strange things

below stil not works
$routes->get('/wpis/(:num)', 'FRONT\Blog::wpis/$1');


RE: another routing problem :) please help - Kordianz - 02-13-2022

my folders structure:
[Image: structure.png]


RE: another routing problem :) please help - Kordianz - 02-13-2022

WORRRKSS!!!

$routes->get('/wpis/(:num)', 'Front\Blog::wpis/$1', ['namespace' => 'App\Controllers']);


RE: another routing problem :) please help - iRedds - 02-13-2022

This is the default namespace.
$routes->setDefaultNamespace('App\Controllers');


RE: another routing problem :) please help - Kordianz - 02-13-2022

Yes, but work with this, without not.
Hmm, maybe: $routes->setDefaultNamespace('App/Controllers'); herer is wrong slash