• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
the created model does not work 'User'

#1
Hello, friends!

dump: 
Code:
CREATE TABLE IF NOT EXISTS `user` (
 `id_user` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `login` char(50) DEFAULT NULL,
 `name` char(50) DEFAULT NULL,
 `email` char(50) DEFAULT NULL,
 `password` char(255) DEFAULT NULL,
 `ip` char(15) DEFAULT NULL,
 `created_at` int(10) unsigned NOT NULL DEFAULT '0',
 `updated_at` int(10) unsigned NOT NULL DEFAULT '0',  
 PRIMARY KEY (`id_user`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

INSERT INTO `user` (`login`, `name`, `email`, `password`, `ip`,`created_at`,`updated_at`) VALUES
('test','Ivan','[email protected]','e1r1e1','10.0.0.1', 1457950515,1457950515);

app\Models\UserModel.php:
Code:
<?php namespace App\Models;

use CodeIgniter\Model;

class UserModel extends Model
{
    protected $table      = 'user';
       protected $primaryKey = 'id_user';

       protected $returnType = 'array';
       protected $useSoftDeletes = true;

       protected $allowedFields = ['login','name', 'email'];

       protected $useTimestamps = true;
       protected $createdField  = 'created_at';
       protected $updatedField  = 'updated_at';
        protected $dateFormat     = 'int';
        
       protected $validationRules    = [];
       protected $validationMessages = [];
       protected $skipValidation     = false;
}

 
app\Controllers\Home.php :

Code:
<?php namespace App\Controllers;
// *LINK REDACTED*
use CodeIgniter\Controller;
use App\Models\UserModel;

class Home extends BaseController
{
    
    puplic function index()
    {
       
        $userModel = new UserModel();
        $user_id = 1;
        $user = $userModel->find($user_id);
    }
}

Result:

Whoops!

We seem to have hit a snag. Please try again later...

--------------
Help me!
Reply

#2
Change id_user to just id I believe that is what it is looking for

Just plain id.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
Understood! id_user nothing to do with!

\ Models \ UserModel.php:

protected $useSoftDeletes = false;

or
protected $useSoftDeletes = true;

but add to the database table field:
`deleted` tinyint(1) unsigned NOT NULL DEFAULT '0'
Reply

#4
Good find! $useSoftDeletes will always presuppose the `deleted` column. For future troubleshooting, if you get "Whoops! We seem to have hit a snag." you can get to the underlying error by checking the log files (might require enabling logging, https://codeigniter4.github.io/CodeIgnit...gging.html) or by setting your environment to "development" which will display the error directly (https://codeigniter4.github.io/CodeIgnit...ments.html).
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.