[Solved] Problem with ci4-adminlte |
Hi everyone.
I hope you can help me with this problem. I downloaded from github ci4 with adminlte3. I noticed that, in the controller, if I put for example: [code] <? php namespace App \ Controllers; use App \ Models \ UserModel; class Users extends BaseController { public $ uModel; public function __construct () { helper ('form'); $ this-> uModel = new UserModel (); } public function index () { $ data ['users'] = $ this-> uModel-> findAll (); return view ('crud / index', $ data); } } [/ code] It tells me that the "users" variable is undefined. It seems to conflict with what is written in 'routes', ($ data). I have tested it on another without adminlte and it works. attached the pastebin https://pastebin.com/KRcsV48G
Take the space out of between $ data should be no spaces in variable names.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
@InsiteFX
if you are referring to the code written in the first message, I apologize it is the translator's fault, in reality I don't have spaces. i tried like this: --Controller: public function index () { / * $data ['users'] = $this->uModel->findAll (); return view ('crud/index', $data); * / return view ('crud/index', [ 'users' => $this->uModel->findAll(), ]); } ---------- --Page <div class = "container"> <div class = "row"> <div class = "col-md-10"> <?php $users = array(); ?> <?php //if(count($users)> 0):?> <table class = "table"> <tr> <th> Id </th> <th> Name </th> <th> Surname </th> <th> Username </th> <th> Email </th> <th> Created </th> <th> Modified </th> <th> Pic </th> </tr> <?php foreach($users as $user): ?> <tr> <td><?= $user->id; ?> </td> <td><?= $user->fname; ?> </td> <td><?= $user->lname; ?> </td> <td><?= $user->uname; ?> </td> <td><?= $user->email; ?> </td> <td><?= $user->created_at; ?> </td> <td><?= $user->updated_at; ?> </td> <td><?= $user->profile_pic; ?> </td> </tr> <?php endforeach; ?> </table> <?php // else:?> <! - <h3> Sorry, no data found. </h3> -> <?php //endif; ?> </div> </div> </div> ------------------- The error is gone, the table appears but not the data. It cannot retrieve data from the database table.
All class names must have the first letter capitalized, you have uModel, UserModel would work.
Controllers, Models, and all class libraries should have the first character capitalized. They should also be saved to file that way. You also need to set the $allowFields and a id What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
I think 'uModel' should work too, as it was stated:
public $uModel; public function __construct() { helper('form'); $this->uModel = new UserModel(); } In 'UserModel' I have: class UserModel extends Model { protected $table = 'users'; protected $primaryKey = 'id'; protected $returnType = 'object'; protected $useSoftDeletes = true; protected $allowedFields = ['uniId', 'fname', 'lname', 'uname', 'email', 'password', 'created_at', 'updated_at', 'status', 'profile_pic', 'activation_date']; In the 'pastebin' file there is everything (unedited) If the same code I insert it outside adminlte => -Controller: Home -Routes: $routes->get('/empview', 'Home::viewEmp'); it works So, maybe I'm wrong, I think it's the code in Routes (the one that handles the 'breadcrumbs') that is giving problems. Do you think you can get around the problem?
WOW - Solved ...
I moved the breadcrumbs code from 'Routes' to the controller and set a traditional address in 'Routes'. So 'Routes' becomes: $routes->get('crud/index', 'Users::index'); and the controller: public function index() { $data = []; $data['users']=$this->uModel->findAll(); $data['title']="AdminLTE 3 | Dashboard 4"; $data['breadcrumb_title']="User List"; $breadcrumb=array( array( 'title' => 'Home', 'link' => 'dashboard' ), array( 'title' => 'User list', 'link' => null ) ); $data['breadcrumb']=$breadcrumb; return view('crud/index',$data); } now I have the answer from the database and in the 'subheader' the breadcrumbs work |
Welcome Guest, Not a member yet? Register Sign In |