how to retrive data from database and display |
hi,
I am beginner, below is my code <?php namespace App\Controllers; use App\Models\product class Product extends BaseController { public function post() { $data = $userModel->findAll(); return view('home',$data); } //-------------------------------------------------------------------- } can you please tell me what is wrong? error message is "Undefined variable: data" how to retrieve data and display in view?
You did not call the model function this code is totally wrong. Actually I did not know your model but you trying to use userModel you need to call out the user model
$userModel = new UserModel(); Then you need to call out the model via namespace use App\Models\UserModel;
(07-08-2020, 12:44 AM)seunex Wrote: You did not call the model function this code is totally wrong. Actually I did not know your model but you trying to use userModel you need to call out the user modelyes i was about to reply saying your not giving us enough information . Also really we need to see how you are doing allowed fields if using CI model and whether your database is set up. I recommend sqlite for easy start can help with that if required (07-08-2020, 12:44 AM)seunex Wrote: You did not call the model function this code is totally wrong. Actually I did not know your model but you trying to use userModel you need to call out the user model Thank you so much. kindly see below code; model: Product.php Code: <?php namespace App\Models; controller: Product.php Code: <?php namespace App\Controllers; view: home.php Code: <?= $this->extend('layout/main')?> how can i stop this error?
Please use code tags when submitting php code ie; [ code] your code here [ /code] remove the space in the tags.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Based on the code provided the only way it can be undefined are this:
Code: $data = array(); Other than that you aren't calling it from somewhere. |
Welcome Guest, Not a member yet? Register Sign In |