Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter 4 Running Problem
#3

(This post was last modified: 09-12-2023, 09:56 AM by captain-sensible.)

difficult to see what your doing and not doing .
So just to clarify routes are in app/Config/Routes.php


when you get /install codeigniter in routes you see :

Code:
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');

so some default stuff set up

for my home page I have in routes :


Code:
$routes->get('/home','Home::landingpage');

so in the above a URL of the domain/home will evoke  Home ::landingpage
i.e function landingpage()   in Home controller


Then to get rid of the welcome to CI4 i made a Home.php controller containing
Code:
<?php

namespace App\Controllers;

class Home extends BaseController
{
            

           public function landingpage()
          
           {
            $data= [
            'title'=>" landing page",
            ];
             return   view('landingPage.php',$data);
           }

             public function index()
          
           {
            $data= [
            'title'=>" landing page",
            ];
             return   view('landingPage.php',$data);
           }


}


you can edit Routes to use another function of your own controller eg

Code:
$routes->get('/', 'Home::index');
// you could have a function in your pages as long as   route ties up with class::class method to be used

then for instance :


Code:
public function index()
          
           {
            $data= [
            'title'=>" landing page",
            ];
             return   view('landingPage.php',$data);
           }

So now domain.com/ or domain.com/home willn ow go to the same landing page

But i guess an edit of default routes might be needed


explantion a bit mangled as i'm in a rush to g oto Aikido , so any questions just come back
CMS CI4     I use Arch Linux by the way 

Reply


Messages In This Thread
CodeIgniter 4 Running Problem - by amitl - 09-12-2023, 06:58 AM
RE: CodeIgniter 4 Running Problem - by ozornick - 09-12-2023, 08:10 AM
RE: CodeIgniter 4 Running Problem - by captain-sensible - 09-12-2023, 09:52 AM
RE: CodeIgniter 4 Running Problem - by kenjis - 09-12-2023, 09:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB