Welcome Guest, Not a member yet? Register   Sign In
using model disalowed in incomingrequest service?
#1

(This post was last modified: 11-08-2023, 09:49 AM by webdeveloper.)

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'
    ];


Reply
#2

(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.
Reply
#3

(This post was last modified: 11-09-2023, 01:00 AM by webdeveloper.)

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB