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

Hi. 

I am new to CodeIgniter 4. I am facing a few problems. Please help to resolve these. 

Environment:
WAMP Server 
PHP 8.1

Installation: 
I am trying to install using Composer. But unable to get version 4.3 but get 4.19. 
Is there any possibility of using install 4.3? 

Problem:
I am following the example documentation of static pages, but receive the below error. 

class_exists() expects parameter 1 to be string, array given


Here is the code. 

Routes.php
Quote:$routes->get('/', 'Home::index');

use App\Controllers\Pages;
$routes->get("/home", [ Pages::class, "index" ]);


Pages.php
Quote:<?php

namespace App\Controllers;

use CodeIgniter\Exceptions\PageNotFoundException;


class Pages extends BaseController
{
  public function index()
  {
    return view("pages/home");
  }
}


home.php
Quote:<h1>Welcome</h1>


Looking forward to resolving the issue.

Awaiting a reply ASAP.


Thanks.
Reply
#2

(This post was last modified: 09-12-2023, 08:10 AM by ozornick.)

Run
Code:
composer require codeigniter4/framework:4.3.8
Reply
#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
#4

(This post was last modified: 09-12-2023, 09:28 PM by kenjis.)

(09-12-2023, 06:58 AM)amitl Wrote: I am trying to install using Composer. But unable to get version 4.3 but get 4.19. 
Is there any possibility of using install 4.3? 

Use PHP 7.4 or later.
It is better to use PHP 8.1 or later.

The end of life date for PHP 7.4 was November 28, 2022. If you are still using PHP 7.4, you should upgrade immediately.
The end of life date for PHP 8.0 will be November 26, 2023.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB