Welcome Guest, Not a member yet? Register   Sign In
  PHPUnit on Production
Posted by: paulkd - 2 hours ago - No Replies

Hi,

CodeIgniter 4.5.1

I'm getting the following message on my production server after deploying with GIT

Code:
Warning: require(/home/project/vendor/composer/../phpunit/phpunit/src/Framework/Assert/Functions.php): Failed to open stream: No such file or directory in /home/project/vendor/composer/autoload_real.php on line 55

Note: I've edited the actual project folder names above.

I've removed "phpunit/phpunit": "^9.5"  from composer.json "require-dev" and run composer update, but it seems that something is still adding it to the composer.lock file

I also have this entry in .gitignore
Code:
# Don't save phpunit under version control.
phpunit

Any help/pointers would be appreciated


  Ci4, CLI Spark Run Standart Command Terminal
Posted by: dhiya as - 2 hours ago - No Replies

hi, is there a function/feature to run the command line outside the spark command?

I am creating an application installation feature via the spark CLI, 
I want to run several commands such as 
"composer require..", "cd", etc, 
these commands are standard from the terminal..can I do that with spark?


  Can't read a session
Posted by: ElTomTom - Yesterday, 11:26 AM - No Replies

We configure our project to use the default suggested by CodeIgniter for session configuration, we only changed the name of the cookie.

We grant the permissions to the session directory in Ubuntu:

Code:
chmod -R 755 writable/
chown -R www-data:www-data writable/


There is no ajax or anything else, just normal access with views.
But as soon as we run the project, the error appears in the log:


PHP Code:
ERROR 2024-05-03 18:19:45 --> SessionUnable to obtain lock for file '/var/www/html/website/writable/session/mysession....4vpq81...psa3h'.
CRITICAL 2024-05-03 18:19:45 --> ErrorExceptionsession_start(): Failed to read session datauser (path: /var/www/html/website/writable/session)
in SYSTEMPATH/Session/Session.php on line 919.
[internal function]: CodeIgniter\Debug\Exceptions->errorHandler()
2 SYSTEMPATH/Session/Session.php(919): session_start()
3 SYSTEMPATH/Session/Session.php(241): CodeIgniter\Session\Session->startSession()
4 SYSTEMPATH/Config/Services.php(699): CodeIgniter\Session\Session->start()
5 SYSTEMPATH/Config/BaseService.php(258): CodeIgniter\Config\Services::session()
6 SYSTEMPATH/Config/BaseService.php(199): CodeIgniter\Config\BaseService::__callStatic()
7 SYSTEMPATH/Config/Services.php(664): CodeIgniter\Config\BaseService::getSharedInstance()
8 SYSTEMPATH/Config/BaseService.php(258): CodeIgniter\Config\Services::session()
9 APPPATH/Controllers/Login.php(16): CodeIgniter\Config\BaseService::__callStatic()
10 SYSTEMPATH/CodeIgniter.php(915): App\Controllers\Login->__construct()
11 SYSTEMPATH/CodeIgniter.php(494): CodeIgniter\CodeIgniter->createController()
12 SYSTEMPATH/CodeIgniter.php(361): CodeIgniter\CodeIgniter->handleRequest()
13 FCPATH/index.php(79): CodeIgniter\CodeIgniter->run() 


PHP Code:
<?php

namespace Config;

use 
CodeIgniter\Config\BaseConfig;
use 
CodeIgniter\Session\Handlers\FileHandler;

class 
Session extends BaseConfig
{

    public string $driver FileHandler::class;

    public string $cookieName 'mysession';

    public int $expiration 7200;

    public string $savePath WRITEPATH 'session';

    public bool $matchIP false;

    public int $timeToUpdate 300;

    public bool $regenerateDestroy false;

    public ?string $DBGroup null;



What could be happening?


Ps.: My php.ini is configured by default to use a session with Redis.


  Unlocking the Power of SQL Queries for Improved Performance
Posted by: InsiteFX - Yesterday, 11:23 AM - No Replies

Unlocking the Power of SQL Queries for Improved Performance


  custom validation dinamic
Posted by: pippuccio76 - Yesterday, 10:04 AM - Replies (3)

hi there is a way to send to parameter to a validation rule ?

Code:
    public function required_if($first_parameter,$second_parameter)
    {

    if(!$first_parameter ){

    return true;

    }else if($first_parameter AND !$second_parameter){
   
    return false;
   
    }else{
   
    return true;
   
    }
   
    }


If is possible how can i pass they in rules ?


Question MaintenanceFilter vs JavaScript
Posted by: Gary - Yesterday, 01:19 AM - No Replies

With all the changes to CI's routing, I'm wondering if there is a clever trick to be able to bypass the Maintenance filter on a (in my case necessary) second entry?

In order to refresh the page (with a "Down for Maintenance" page), it is necessary to initiate a page refresh... which is easy enough to initiate in the (now enabled) MainenanceFilter.  The problem is that this means there is now a second request (redirection) coming in from the client... which then gets repeatedly caught by the MaintenanceFilter.

I have patched it with a few new $_SESSION variables... to indicate that it's a reentry call... and also some changed to the users' $_SESSION (so as to disable the users' control/input, in such a manner that the session can be be restored/re-enabled, if the maintenance outage is only going to be brief).

So the question is... although I have it working, there are messy (and seldom required) $_SESSION checks and processing now dotted around elsewhere in the code, which irritates me... is there a more elegant way of handling this need for the reentry/second run though the Filter/s?


  Trying to remove index.php from url in latest codeigniter 4.5.1
Posted by: kabeza - 05-02-2024, 08:57 AM - Replies (5)

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 - 05-02-2024, 08:06 AM - Replies (5)

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.


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

Username
  

Password
  





Latest Threads
custom validation dinamic
by ozornick
1 hour ago
PHPUnit on Production
by paulkd
2 hours ago
Ci4, CLI Spark Run Standa...
by dhiya as
2 hours ago
Reading a session variabl...
by kenjis
6 hours ago
Can't read a session
by ElTomTom
Yesterday, 11:26 AM
Unlocking the Power of SQ...
by InsiteFX
Yesterday, 11:23 AM
Convert Filters to Regist...
by ozornick
Yesterday, 10:24 AM
Cannot access protected p...
by ozornick
Yesterday, 10:14 AM
request URL not found
by jcarvalho
Yesterday, 07:45 AM
Trying to remove index.ph...
by demyr
Yesterday, 05:31 AM

Forum Statistics
» Members: 86,304
» Latest member: Olympus Construction
» Forum threads: 77,611
» Forum posts: 376,150

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB