Welcome Guest, Not a member yet? Register   Sign In
  Trying to remove index.php from url in latest codeigniter 4.5.1
Posted by: kabeza - Yesterday, 08:57 AM - Replies (3)

Hi
I've started a new codeigniter 4.5.1 appstarter project at my PC and am having difficult time to remove the index.php from uri

1) This is the virtualhost set in my Apache. Points at public as suggested

Code:
<VirtualHost *:80>
    ServerAdmin admin@localhost
    ServerName sw
    ServerAlias sw
    DocumentRoot /media/data/services/public
    <Directory /media/data/services/public>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error_sw.log
    CustomLog ${APACHE_LOG_DIR}/access_sw.log combined
</VirtualHost>

2) I've enabled the mod_rewrite, restarted apache, edited /etc/hosts file. Then I browse to http://sw , which shows the codeigniter welcome, great!

3) I rename the root/env file to .env and leave it with

Code:
#--------------------------------------------------------------------
# APP
#--------------------------------------------------------------------
CI_ENVIRONMENT = development
app.baseURL = 'http://sw'
app.indexPage = ''

4) I define a new route in app/config/Routes.php

Code:
$routes->get('/services', 'Services::index');

Then, my controller app/Controllers/Services.php looks like

PHP Code:
<?php

namespace App\Controllers;

class 
Services extends BaseController
{
    public function index(): string
    
{
        return view('view_services');
    }


Then, when I try this url in browser

http://sw/services

I'm getting 404 ...

5) Tried also replacing the public/.htaccess with the suggested in
https://codeigniter.com/user_guide/gener...x-php-file
No luck

6) I've also tried setting the baseURL, indexPage, etc. options in app/Config/App.php without luck

I've got no ideas left to solve this
Thanks for any suggestion


  Convert Filters to Registrar
Posted by: Willen - Yesterday, 08:06 AM - Replies (1)

Hello! 

I am having a little bit of trouble understanding the deprecation of Filters in favor of Registrars. I need some help in order to get my head around how Registrars work and what the pros are compared to the now deprecated Filters-way of doing things.
To convert my Filters to Registrar, I tried to follow the minimal instruction in the deprecated-note on the documentation-page. Since it does not cover much, I am not sure if I have done it correctly and what else I need to do. I have created a Registrar.php file in the Config-folder, where my filters are defined following the structure in the example:

Code:
<?php namespace App\Config;

use App\Filters\{AuthFilter, Cors, AdminFilter};

class Registrar {
  public static function Filters(): array {
    return [
      'aliases' => [
        'authFilter' => AuthFilter::class,
        'cors' => Cors::class,
        'adminFilter' => AdminFilter::class,
      ],
    ];
  }
}

I am a little unsure of what more I need to do, if anything? Should I change anything in the actual Filters-files? Can I remove the Filters from the $aliases list in Filters.php? Does it change the way I use the Filters in the Routes file?
I currently have three filters; Cors, AdminFilter and AuthFilter. These filters are being used before certain routes. For example, the AuthFilter makes sure a request is authenticated before letting the request through to its respective endpoint. My Cors filter handles Cors, and runs before any request. These filters work flawlessly with the now deprecated Filter-structure, but I do not get how I use them in my Routes the Registrars way. This is how my routes look now:

Code:
$routes->group('', ['filter' => 'cors'], static function (RouteCollection $routes): void {

  $routes->group('auth', static function ($routes) {
    $routes->options('login', 'Auth::login');
    $routes->post('login', 'Auth::login');
    $routes->options('refresh_token', 'Auth::refresh_token');
    $routes->get('refresh_token', 'Auth::refresh_token', ['filter' => 'authFilter']);
  });

  $routes->group('users', static function ($routes) {
    $routes->options('get_all_users', 'Users::get_all_users');
    $routes->get('get_all_users', 'Users::get_all_users', ['filter' => 'authFilter']);
    $routes->options('delete_user_by_username', 'Users::delete_user_by_username');
    $routes->delete('delete_user_by_username', 'Users::delete_user_by_username', ['filter' => 'adminFilter']);
    $routes->options('add_user', 'Users::add_user');
    $routes->post('add_user', 'Users::add_user', ['filter' => 'adminFilter']);
  });


I made these filters a while ago, so I was not aware of Codeigniters own Cors-filter. But now that I have looked into it, it also uses the Filter-way of doing things and not the Registrar-way. Filters was set to deprecated in 4.2, how come a new feature that is introduced in 4.5 use a deprecated way of doing things?


  Filters in filters folder. how to use them?
Posted by: xsPurX - 05-01-2024, 03:01 PM - No Replies

Might seem like a dumb question, but I created this filter below, I am using Shield, I want the user to be redirected when accessing a protected controller. Right now it redirects to /login. and I want it to go to /pages/view/Login
I added this filter, but how do I use it?

Code:
<?php
namespace App\Filters;

use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;

class LoggedIn implements FilterInterface
{
    public function before(RequestInterface $request, $arguments = null)
    {
    $auth = service('auth');
        if (!$auth()->loggedIn()) {
            return redirect()->to(site_url('pages/view/Login'));
        }
    }

    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
    {

    }
}

Ok I just added it as an alias,
Code:
    public array $aliases = [
        'csrf'          => CSRF::class,
        'toolbar'      => DebugToolbar::class,
        'honeypot'      => Honeypot::class,
        'invalidchars'  => InvalidChars::class,
        'secureheaders' => SecureHeaders::class,
        'LoggedIn'      => \App\Filters\LoggedIn::class,
    ];

Then added a filter like below, and that works.
Code:
'LoggedIn' => ['before' => ['dashboard', 'dashboard/*']],


  codeigniter.com/user_guide is not updated
Posted by: defcon0 - 05-01-2024, 02:51 PM - Replies (4)

Hi everybody.
The guys who update the Codeigniter user guide website have stopped in version 4.4.5.
The latest version 4.5.1 has no information about change logs and how to upgrade from previous version.
https://codeigniter.com/user_guide/chang...index.html
https://codeigniter.com/user_guide/insta...ading.html
https://codeigniter.com/user_guide/insta...e_501.html
Please help us with it.
Thank you in advance.


  Request URL 404 Amazon EC
Posted by: robrym - 05-01-2024, 01:04 PM - No Replies

Could someone kindly assist me with the following situation? I've been racking my brains for days and haven't found a solution.
I have been developing on localhost for the past couple of months, recently I uploaded my project to amazon EC, followed the same process as I did on my local installation but for some reason it keeps giving me error 404 if I try to access on of the routes.

This is my home page: http://dev.kosheradmin.com/ and it shows me the basic code igniter page.

And this is one of my routes: http://dev.kosheradmin.com/api/users 
And this is my .htaccess on public:

# Disable directory browsing
Options -Indexes

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
        Options +FollowSymlinks
        RewriteEngine On

        # If you installed CodeIgniter in a subfolder, you will need to
        # change the following line to match the subfolder you need.
        # http://httpd.apache.org/docs/current/mod...ewritebase
        # RewriteBase /

        # Redirect Trailing Slashes...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (.+)/$
        RewriteRule ^ %1 [L,R=301]

        # Rewrite "www.example.com -> example.com"
        RewriteCond %{HTTPS} !=on
        RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
        RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

        # Checks to see if the user is attempting to access a valid file,
        # such as an image or css document, if this isn't true it sends the
        # request to the front controller, index.php
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d


       # Redirect Trailing Slashes...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (.+)/$
        RewriteRule ^ %1 [L,R=301]

        # Rewrite "www.example.com -> example.com"
        RewriteCond %{HTTPS} !=on
        RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
        RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

        # Checks to see if the user is attempting to access a valid file,
        # such as an image or css document, if this isn't true it sends the
        # request to the front controller, index.php
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]

        # Ensure Authorization header is passed along
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

<IfModule !mod_rewrite.c>
        # If we don't have mod_rewrite installed, all 404's
        # can be sent to index.php, and everything works as normal.
        ErrorDocument 404 index.php
</IfModule>

# Disable server signature start
        ServerSignature Off
# Disable server signature end


  Top 10 PHP Testing Frameworks for 2024 (Dev.to)
Posted by: php_rocs - 05-01-2024, 07:54 AM - Replies (2)

https://dev.to/lambdatest/top-10-php-tes...-2024-4gee


  CL4 Connecting to a Remote AWS Database
Posted by: cx3700 - 04-30-2024, 08:04 PM - Replies (5)

CL 4.5.1 running on AWS Ubuntu with Plesk.

I am trying to connect to a database on our AWS test server from our AWS production server. 

When I connect to a local db on production it works but the remote (test) db connection throws a 500 error, but I can't see what the exact error is. 

Port 3306 is open on both AWS instances. 

I have set allow access from all sources. 

I have tried both the IP address and domain name in the hostname property.

Any advice?


PHP Code:
    public array $default = [
        'DSN'      => '',
        'hostname' => '54.200.xxx.xxx',
        'username' => 'test',
        'password' => 'password123',
        'database' => 'test',
        'DBDriver' => 'MySQLi',
        'DBPrefix' => '',
        'pConnect' => false,
        'DBDebug'  => true,
        'charset'  => 'utf8',
        'DBCollat' => 'utf8_general_ci',
        'swapPre'  => '',
        'encrypt'  => false,
        'compress' => false,
        'strictOn' => false,
        'failover' => [],
        'port'    => 3306,
    ]; 

The Error

Uncaught Error.
{
    "title": "CodeIgniter\\Database\\Exceptions\\DatabaseException",
    "type": "CodeIgniter\\Database\\Exceptions\\DatabaseException",
    "code": 500,
    "message": "Unable to connect to the database.\nMain connection [MySQLi]: Connection refused",
    "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/system/Database/BaseConnection.php",
    "line": 428,
    "trace": [
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/system/Database/BaseConnection.php",
            "line": 575,
            "function": "initialize",
            "class": "CodeIgniter\\Database\\BaseConnection",
            "type": "->"
        },
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/app/Models/ChecklistModel.php",
            "line": 35,
            "function": "query",
            "class": "CodeIgniter\\Database\\BaseConnection",
            "type": "->"
        },
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/app/Controllers/Checklist.php",
            "line": 58,
            "function": "getSiteByPVIN",
            "class": "App\\Models\\ChecklistModel",
            "type": "->"
        },
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/app/Controllers/Checklist.php",
            "line": 48,
            "function": "get_site_information",
            "class": "App\\Controllers\\Checklist",
            "type": "->"
        },
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/system/CodeIgniter.php",
            "line": 943,
            "function": "check_site_information",
            "class": "App\\Controllers\\Checklist",
            "type": "->"
        },
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/system/CodeIgniter.php",
            "line": 503,
            "function": "runController",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->"
        },
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/system/CodeIgniter.php",
            "line": 361,
            "function": "handleRequest",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->"
        },
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/public/index.php",
            "line": 79,
            "function": "run",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->"
        }
    ]
}


  Basic Algorithms
Posted by: InsiteFX - 04-30-2024, 01:56 AM - No Replies

Basic Algorithms

Algorithms are the lifeblood of computing. They are the step-by-step instructions that computers
follow to solve problems, analyze data, and make decisions. Just like recipes, they break down
complex tasks into manageable procedures. Understanding these fundamental algorithms is a stepping
stone to mastering computer science and programming.


  What should I do to show deprecations errors in the output?
Posted by: mywebmanavgat - 04-29-2024, 05:12 PM - Replies (1)

When I examine the logs in a project I am developing with Codeigniter 4, there are Deprecations log records for some of the codes I use.

How can I ensure that codeigniter throws an exception to the screen when it receives such an error, at least when developer mode is on?


  request URL not found
Posted by: jcarvalho - 04-29-2024, 03:52 PM - Replies (6)

Hi guys, I am struggling to make my CI4 app to work properly in an internal LAN linux machine, I have installed Apache,php 8.3 and mySql in xubuntu 22.04 LTS
The rewrite mod is enable in Apache.
I made several tries with a a .conf file in /etc/apache2/sites-enabled, nothing work. My current file is
I do sudo a2ensite and the filename and restart apache2

Code:
<VirtualHost *:80>
    #ServerName 192.168.0.18
  ServerAlias /b2bci4
  DocumentRoot "/var/www/html/b2bci4/public"
    <Directory "/var/www/html/b2bci4">
        Options Indexes FollowSymLinks MultiViews
        #Options  +FollowSymLinks
        AllowOverride All
        #Order allow,deny
        #allow from all
        Require all granted
  </Directory>
</VirtualHost>

I have place an .htaccess file like in the CI4 web site
Code:
#RewriteEngine On
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
<FilesMatch "^\.">
    Require all denied
    Satisfy All
</FilesMatch>

In app/Config/App.php I have public string $baseURL = 'http://192.168.0.18/b2bci4/public/';

I can get the login screen but when I click submit to the controller Login/doLogin I got 404... All is working right in my xampp when I start spark server and do http://localhost:8080

Can someone point me what I am doing wrong please?

Thank you all!


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
Trying to remove index.ph...
by kenjis
6 hours ago
Convert Filters to Regist...
by kenjis
6 hours ago
Top 10 PHP Testing Framew...
by FlavioSuar
Yesterday, 04:00 AM
CL4 Connecting to a Remot...
by cx3700
05-01-2024, 07:33 PM
codeigniter.com/user_guid...
by kenjis
05-01-2024, 07:29 PM
As experienced web develo...
by kenjis
05-01-2024, 06:03 PM
Filters in filters folder...
by xsPurX
05-01-2024, 03:01 PM
Request URL 404 Amazon EC
by robrym
05-01-2024, 01:04 PM
Integrating Bootstrap 5 i...
by captain-sensible
05-01-2024, 09:17 AM
request URL not found
by captain-sensible
05-01-2024, 09:04 AM

Forum Statistics
» Members: 86,146
» Latest member: lashculture
» Forum threads: 77,603
» Forum posts: 376,119

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB