CI4 Model Is huge - Mazen - 09-03-2023
I'm facing an Issue in my CI4 project,
I override the mode returnType to be self::class [To handle the relation between the models]
When I'm trying to var_dump the model, I got a huge object contains the AutoLoad, FileLocator, .. etc
Which causes a Memory Limit error
How can I fix it?
RE: CI4 Model Is huge - ozornick - 09-03-2023
Your server seems to have too little RAM.
RE: CI4 Model Is huge - Mazen - 09-03-2023
(09-03-2023, 03:22 AM)ozornick Wrote: Your server seems to have too little RAM.
No, It's 16GB ram, I'm talking about the model object, why it has the autoloader classes?
The issue occurred after I installed the google-sdk which has a lot of classes, so now when var_dump the model, I'll see all autoloaded classes!
RE: CI4 Model Is huge - ozornick - 09-03-2023
Try d($model) from Kint package
Or install
Code: composer require --dev symfony/var-dumper
Add functions dump() and dd()
RE: CI4 Model Is huge - kenjis - 09-03-2023
This is the default Model object. It is not small, but does not have AutoLoad, FileLocator.
Code: .../CodeIgniter4/app/Controllers/Home.php:12:
object(CodeIgniter\Model)[65]
public 'pager' => null
protected 'insertID' => int 0
protected 'DBGroup' => null
protected 'returnType' => string 'array' (length=5)
protected 'useSoftDeletes' => boolean false
protected 'allowedFields' =>
array (size=0)
empty
protected 'useTimestamps' => boolean false
protected 'dateFormat' => string 'datetime' (length=8)
protected 'createdField' => string 'created_at' (length=10)
protected 'updatedField' => string 'updated_at' (length=10)
protected 'tempUseSoftDeletes' => boolean false
protected 'deletedField' => string 'deleted_at' (length=10)
protected 'tempReturnType' => string 'array' (length=5)
protected 'protectFields' => boolean true
protected 'db' =>
object(CodeIgniter\Database\MySQLi\Connection)[68]
protected 'DSN' => string '' (length=0)
protected 'port' => int 3306
protected 'hostname' => string 'localhost' (length=9)
protected 'username' => string 'root' (length=4)
protected 'password' => string '' (length=0)
protected 'database' => string 'ci4' (length=3)
public 'DBDriver' => string 'MySQLi' (length=6)
protected 'subdriver' => null
protected 'DBPrefix' => string '' (length=0)
protected 'pConnect' => boolean false
protected 'DBDebug' => boolean true
protected 'charset' => string 'utf8' (length=4)
protected 'DBCollat' => string 'utf8_general_ci' (length=15)
protected 'swapPre' => string '' (length=0)
protected 'encrypt' => boolean false
protected 'compress' => boolean false
protected 'strictOn' => boolean false
protected 'failover' =>
array (size=0)
empty
protected 'lastQuery' => null
public 'connID' => boolean false
public 'resultID' => boolean false
public 'protectIdentifiers' => boolean true
protected 'reservedIdentifiers' =>
array (size=1)
0 => string '*' (length=1)
public 'escapeChar' => string '`' (length=1)
public 'likeEscapeStr' => string ' ESCAPE '%s' ' (length=13)
public 'likeEscapeChar' => string '!' (length=1)
protected 'pregEscapeChar' =>
array (size=0)
empty
public 'dataCache' =>
array (size=0)
empty
protected 'connectTime' => float 0
protected 'connectDuration' => float 0
protected 'pretend' => boolean false
public 'transEnabled' => boolean true
public 'transStrict' => boolean true
protected 'transDepth' => int 0
protected 'transStatus' => boolean true
protected 'transFailure' => boolean false
protected bool 'transException' => boolean false
protected 'aliasedTables' =>
array (size=0)
empty
protected 'queryClass' => string 'CodeIgniter\Database\Query' (length=26)
public 'deleteHack' => boolean true
public 'mysqli' => null
public 'resultMode' => int 0
public 'numberNative' => boolean false
protected 'validationRules' =>
array (size=0)
empty
protected 'validationMessages' =>
array (size=0)
empty
protected 'skipValidation' => boolean false
protected 'cleanValidationRules' => boolean true
protected 'validation' =>
object(CodeIgniter\Validation\Validation)[70]
protected 'ruleSetFiles' =>
array (size=4)
0 => string 'CodeIgniter\Validation\StrictRules\Rules' (length=40)
1 => string 'CodeIgniter\Validation\StrictRules\FormatRules' (length=46)
2 => string 'CodeIgniter\Validation\StrictRules\FileRules' (length=44)
3 => string 'CodeIgniter\Validation\StrictRules\CreditCardRules' (length=50)
protected 'ruleSetInstances' =>
array (size=4)
0 =>
object(CodeIgniter\Validation\StrictRules\Rules)[73]
...
1 =>
object(CodeIgniter\Validation\StrictRules\FormatRules)[75]
...
2 =>
object(CodeIgniter\Validation\StrictRules\FileRules)[77]
...
3 =>
object(CodeIgniter\Validation\StrictRules\CreditCardRules)[78]
...
protected 'rules' =>
array (size=0)
empty
protected 'data' =>
array (size=0)
empty
protected 'validated' =>
array (size=0)
empty
protected 'errors' =>
array (size=0)
empty
protected 'customErrors' =>
array (size=0)
empty
protected 'config' =>
object(Config\Validation)[69]
public array 'ruleSets' =>
array (size=4)
...
public array 'templates' =>
array (size=2)
...
protected 'view' =>
object(CodeIgniter\View\View)[72]
protected 'data' =>
array (size=0)
...
protected 'tempData' => null
protected 'viewPath' => string '.../CodeIgniter4/app/Config/../Views/' (length=72)
protected 'renderVars' =>
array (size=0)
...
protected 'loader' =>
object(CodeIgniter\Autoloader\FileLocator)[4]
...
protected 'logger' =>
object(CodeIgniter\Log\Logger)[63]
...
protected 'debug' => boolean true
protected 'performanceData' =>
array (size=0)
...
protected 'config' =>
object(Config\View)[71]
...
protected 'saveData' => boolean true
protected 'viewsCount' => int 0
protected 'layout' => null
protected 'sections' =>
array (size=0)
...
protected 'currentSection' => null
protected 'sectionStack' =>
array (size=0)
...
protected 'allowCallbacks' => boolean true
protected 'tempAllowCallbacks' => boolean true
protected 'beforeInsert' =>
array (size=0)
empty
protected 'afterInsert' =>
array (size=0)
empty
protected 'beforeUpdate' =>
array (size=0)
empty
protected 'afterUpdate' =>
array (size=0)
empty
protected 'beforeInsertBatch' =>
array (size=0)
empty
protected 'afterInsertBatch' =>
array (size=0)
empty
protected 'beforeUpdateBatch' =>
array (size=0)
empty
protected 'afterUpdateBatch' =>
array (size=0)
empty
protected 'beforeFind' =>
array (size=0)
empty
protected 'afterFind' =>
array (size=0)
empty
protected 'beforeDelete' =>
array (size=0)
empty
protected 'afterDelete' =>
array (size=0)
empty
protected bool 'allowEmptyInserts' => boolean false
protected 'table' => null
protected 'primaryKey' => string 'id' (length=2)
protected 'useAutoIncrement' => boolean true
protected 'builder' => null
protected 'tempData' =>
array (size=0)
empty
protected 'escape' =>
array (size=0)
empty
private array 'builderMethodsNotAvailable' =>
array (size=3)
0 => string 'getCompiledInsert' (length=17)
1 => string 'getCompiledSelect' (length=17)
2 => string 'getCompiledUpdate' (length=17)
RE: CI4 Model Is huge - Mazen - 09-05-2023
(09-03-2023, 07:49 PM)kenjis Wrote: This is the default Model object. It is not small, but does not have AutoLoad, FileLocator.
So, What's the issue with my code? why the model class have autoLoad files?
RE: CI4 Model Is huge - luckmoshy - 09-05-2023
@Mazen Yep, if you use PSR4 autoload, this is what you should expect. If I am not mistaken, at an earlier time something like this happened, so bear this in mind if you play with the module Take care: How do you organize your class and methods?
RE: CI4 Model Is huge - kenjis - 09-05-2023
Ah, there is CodeIgniter\Autoloader\FileLocator in CodeIgniter\View\View in CodeIgniter\Validation\Validation.
I seem to have overlooked it.
Code: protected 'validation' =>
object(CodeIgniter\Validation\Validation)[70]
protected 'ruleSetFiles' =>
array (size=4)
0 => string 'CodeIgniter\Validation\StrictRules\Rules' (length=40)
1 => string 'CodeIgniter\Validation\StrictRules\FormatRules' (length=46)
2 => string 'CodeIgniter\Validation\StrictRules\FileRules' (length=44)
3 => string 'CodeIgniter\Validation\StrictRules\CreditCardRules' (length=50)
protected 'ruleSetInstances' =>
array (size=4)
0 =>
object(CodeIgniter\Validation\StrictRules\Rules)[73]
...
1 =>
object(CodeIgniter\Validation\StrictRules\FormatRules)[75]
...
2 =>
object(CodeIgniter\Validation\StrictRules\FileRules)[77]
...
3 =>
object(CodeIgniter\Validation\StrictRules\CreditCardRules)[78]
...
protected 'rules' =>
array (size=0)
empty
protected 'data' =>
array (size=0)
empty
protected 'validated' =>
array (size=0)
empty
protected 'errors' =>
array (size=0)
empty
protected 'customErrors' =>
array (size=0)
empty
protected 'config' =>
object(Config\Validation)[69]
public array 'ruleSets' =>
array (size=4)
...
public array 'templates' =>
array (size=2)
...
protected 'view' =>
object(CodeIgniter\View\View)[72]
protected 'data' =>
array (size=0)
...
protected 'tempData' => null
protected 'viewPath' => string '.../CodeIgniter4/app/Config/../Views/' (length=72)
protected 'renderVars' =>
array (size=0)
...
protected 'loader' =>
object(CodeIgniter\Autoloader\FileLocator)[4]
RE: CI4 Model Is huge - Mazen - 09-06-2023
(09-05-2023, 07:05 AM)luckmoshy Wrote: @Mazen Yep, if you use PSR4 autoload, this is what you should expect. If I am not mistaken, at an earlier time something like this happened, so bear this in mind if you play with the module Take care: How do you organize your class and methods?
All my relations is inside the model, so once I find any model I need the returnType to be self::class
For Example:
class User extends Model {
public function posts() {
return (new Post())->where(['user_id' => $this->id])->findAll();
}
}
So I decided to skip model validation and set the validation object to null as following
$this->validation = null;
$this->skipValidation();
and move all validation rules to the requests classes by using Service::validation()->run($data) instead of using $model->validate($data);
RE: CI4 Model Is huge - kenjis - 10-24-2023
I sent a PR: https://github.com/codeigniter4/CodeIgniter4/pull/8087
|