This question already has answers here:
How to load a controller from another controller in codeigniter?
(10 answers)
Closed 4 years ago.
I have the Login_controller:
if ($query->num_rows() == 1){
$usuario = $query->row();
$this->load->library('../controllers/Dashboard_controller');
}
And I have the Dashboard_Controller:
public function index(){
$this->load->view("dashboard/Dashboard_view");
}
}
But, I got a message error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Dashboard_controller::$load
Filename: libraries/Form_validation.php
Line Number: 147
Backtrace:
File: C:\xampp\htdocs\local\acjum1\application\controllers\Login_controller.php
Line: 34
Function: library
File: C:\xampp\htdocs\local\acjum1\index.php
Line: 315
Function: require_once
An uncaught Exception was encountered
Type: Error
Message: Call to a member function helper() on null
Filename: C:\xampp\htdocs\local\acjum1\system\libraries\Form_validation.php
Line Number: 147
Backtrace:
File: C:\xampp\htdocs\local\acjum1\application\controllers\Login_controller.php
Line: 34
Function: library
File: C:\xampp\htdocs\local\acjum1\index.php
Line: 315
Function: require_once
What am I doing wrong?
Try this one
redirect('/dashboard/index');
This question was asked before.
Basically you are calling the controller but not the index function.
Please refer to : How to load a controller from another controller in codeigniter?
Related
I've moved from PHP5 to PHP7.
The following code no longer works.
<?php
class sandbox {
function doit() {
$method = array('name' => 'testresponse');
return $this->$method['name']();
}
function testresponse(){
return "Hi!";
}
}
$h = new sandbox();
echo "Hello, " . $h->doit();
I'm wondering what is the new syntax for this?
Here are the PHP errors I'm getting
A PHP Error was encountered Severity: Notice
Severity: Notice
Message: Array to string conversion
Filename: front/sandbox.php
Line Number: 20
And
Fatal error: Uncaught Error: Function name must be a string in /var/www/application/controller/sandbox.php:20 Stack trace: #0
Change this
return $this->$method['name']();
to this
return $this->{$method['name']}();
I get these errors when I go the Reports.php page:
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 0
Filename: controllers/Reports.php
Line Number: 73
Backtrace:
File: C:\xampp\htdocs\restaurant\application\controllers\Reports.php
Line: 73
Function: _error_handler
File: C:\xampp\htdocs\restaurant\index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: controllers/Reports.php
Line Number: 88
Backtrace:
File: C:\xampp\htdocs\restaurant\application\controllers\Reports.php
Line: 88
Function: _error_handler
File: C:\xampp\htdocs\restaurant\index.php
Line: 315
Function: require_once
This is line 73 in Reports.php:
$store_id = $store_data[0]['id'];
This is line 88 in Reports.php:
foreach ($order_data as $k => $v) {
This is line 315 in index.php:
require_once BASEPATH.'core/CodeIgniter.php';
A PHP Error was encountered
Severity: Error
Message: Call to undefined method Post::where()
Filename: models/post.php
Line Number: 23
This is my edit controller
function editpost($postID){
$data['success']=0;
if($_POST){
$data_post=array(
'title'=>$_POST['title'],
'post'=>$_POST['post'],
'active'=>1
);
$this->post->update_post($postID,$data_post);
$data['success']=1;
}
$data['post']=$this->post->get_post($postID);
$this->load->view('edit_post',$data);
}
this is my update model
function update_post($postID,$data){
$this->where('postID',$postID);
$this->db->update('posts',$data);
}
I changed the data_post - data same error
Where is my error?
put $this->db->where('postID',$postID);
$this->db->update('posts',$data) in your model code
Follow bellow code:
function update_post($postID,$data){
$this->db->where('postID',$postID);
$this->db->update('posts',$data);
}
Please change your update_post function code from $this->where('postID',$postID);
to $this->db->where('postID',$postID);. You missing ->db before ->where condition in your model page.
Thanks
I'm trying to join my table and it's working but I don't know why I got the following error messages.
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: get
Filename: views/tambah_wali.php
Line Number: 13
Fatal error: Call to a member function result() on a non-object in C:\xampp\htdocs\ujikom_sekolah\application\views\tambah_wali.php on line 13
This is my controller:
public function tambah_wali($kode){
$data['get']=$this->madm->join_wali_siswa($kode);
$this->load->view('tambah_wali');
}
This is my model:
public function join_wali_siswa($kode) {
$this->db->select('wali_murid.nisn');
$this->db->from('siswa');
$this->db->join('wali_murid','siswa.nisn=wali_murid.nisn','right');
$this->db->where('siswa.nisn',$kode);
$query=$ambildata=$this->db->get();
if($ambildata->num_rows > 0)
return $query;
else
return null;
}
This is line 13 on my view:
<?php foreach($get->result() as $row): ?>
Load your $data['get'] in your view seems to be missing when have a $data variable must add it to view like below.
$data['get'] = $this->madm->join_wali_siswa($kode);
$this->load->view('tambah_wali', $data);
For some reason i cant get my model to work.. never had this problem before.
function overview($userid)
{
// Load needed model
$this->load->model('budget_model');
$data['month_budget'] = $this->budget_model->get_monthly_budget($userid);
if(isset($_POST['submit']))
{
foreach($_POST as $key => $value)
{
if(is_numeric($key))
{
$this->buget_model->update_buget($key,$value);
echo "DONE";
}
}
echo "<pre>";
print_r($_POST);
echo "</pre>";
}
$data['main'] = 'super_admin/budget_edit_overview_view';
$this->load->view('default/main_view',$data);
}
The model works fine with "$this->budget_model->get_monthly_budget($userid);" but i keep getting thir error,
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Admin::$buget_model
Filename: controllers/admin.php
Line Number: 166
Fatal error: Call to a member function update_buget() on a non-object
in /Applications/MAMP/htdocs/therace/application/controllers/admin.php
on line 166
The model method,
function update_buget($id,$budget)
{
$this->db->where('id', $id);
// Update the month budget
$data = array(
'month_goal' => $budget
);
$this->db->update('budget_month', $data);
return true;
}
Read the error message carefully:
Message: Undefined property: Admin::$buget_model
Did you make a typo and actually mean $budget_model?
edit: There seems to be a lot of budget vs. buget in your code. I suggest a spellchecker.
You have made a typing error in line 166.
It is $this->budget_model->update_buget($key,$value);
not $this->buget_model->update_buget($key,$value);