CodeIgniter Forums
using model disalowed in incomingrequest service? - 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: using model disalowed in incomingrequest service? (/showthread.php?tid=88795)



using model disalowed in incomingrequest service? - webdeveloper - 11-08-2023

Hello, i literally cannot find out what's wrong with my custom incomingrequest service. Are the models disallowed here?

After i remove line with $domainModel = new DomainModel(); everything works fine.


Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 8192 bytes) in /var/www/admin/vendor/codeigniter4/framework/system/HTTP/IncomingRequest.php on line 169
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 8192 bytes) in /var/www/admin/vendor/codeigniter4/framework/system/HTTP/IncomingRequest.php on line 169


app/Services/IncomingRequest.php

PHP Code:
<?php

namespace App\Services;

use 
App\Models\DomainModel;
use 
CodeIgniter\HTTP\URI;
use 
CodeIgniter\HTTP\UserAgent;
use 
Exception;

class 
IncomingRequest extends \CodeIgniter\HTTP\IncomingRequest
{
    /**
    * @param                $config
    * @param URI|null      $uri
    * @param string        $body
    * @param UserAgent|null $userAgent
    *
    * @throws Exception
    */
    public function __construct($configURI $uri null$body 'php://input'UserAgent $userAgent null) {
        parent::__construct($config$uri$body$userAgent);

        $domainModel = new DomainModel();

    }



app/Config/Services.php

PHP Code:
<?php

namespace Config;

use 
App\Services\IncomingRequest as IncomingRequestApp;
use 
CodeIgniter\Config\BaseService;
use 
CodeIgniter\HTTP\UserAgent;
use 
Exception;

class 
Services extends BaseService
{
    /**
    * @param App|null $config
    * @param bool    $getShared
    *
    * @return object
    * @throws Exception
    */
    public static function incomingrequest(?App $config nullbool $getShared true): object {
        if ($getShared) {
            return static::getSharedInstance('request'$config);
        }

        $config ??= config(App::class);

        return new IncomingRequestApp(
            $config,
            static::uri(),
            'php://input',
            new UserAgent()
        );
    }



app/Models/DomainModel.php



PHP Code:
<?php

namespace App\Models;

use 
CodeIgniter\Model;

class 
DomainModel extends Model
{
    protected $table 'domain';

    protected $primaryKey 'domain_id';

    protected $allowedFields = [
        'domain_name',
        'ga_code_u',
        'ga_code_4',
        'title',
        'social_fb',
        'phone',
        'email',
        'address'
    ];





RE: using model disalowed in incomingrequest service? - kenjis - 11-08-2023

(11-08-2023, 09:48 AM)webdeveloper Wrote: Hello, i literally cannot find out what's wrong with my custom incomingrequest service. Are the models disallowed here?

No, but it is quite bad design.
IncomingRequest should not know Models.
I recommend you don't do like that.


RE: using model disalowed in incomingrequest service? - webdeveloper - 11-09-2023

Evidently there is problem.

In version 4.4.1 worked fine until 4.4.3.

How dynamically load languages from database, so i can use them in filters? DomainModel did this for me on this place so i worked all over other places with custom supportedLangs.