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);
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']}();
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);
I have an error in my project, can you please help me? Here's my code :
$q_cek_login = $this->db->get_where('tbl_karyawan', array('username' => $u, 'password' => $p));
if(count($q_cek_login->result())>0)
{
foreach($q_cek_login->result() as $qck)
{
if($qck->id_jabatan==1)
{
foreach($q_cek_login->result() as $qad)
{
$sess_data['logged_in'] = 'yesGetMeLogin';
$sess_data['username'] = $qad->username;
$sess_data['nama_pengguna'] = $qad->nama;
$sess_data['id_jabatan'] = $qad->id_jabatan;
$this->session->set_userdata($sess_data);
}
//header('location:'.base_url().'pemesanan/pending');
}
}
}
Then I get this error :
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$id_jabatan
Filename: models/model_digor.php
Line Number: 26
thx u all..........
Please check your dependency class is loaded properly. such as $this->load->library('database'); or $this->load->library('your_built_in_class');
Notice: Undefined variable: entryMessage in /var/www/Employee/application/models/EmployeeMapper.php on line 34 Fatal error: Call to a member function setEmployeeId() on a non-object in /var/www/Employee/application/models/EmployeeMapper.php on line 34
This is the error i am getting i try to display the entered fields , I checked the database and the fields are getting saved , I am posting the Employee Mapper .Please check the code and tell a solution , thanks in advance
class Application_Model_EmployeeMapper
{
protected $_dbTable;
public function setDbTable($dbTable)
{
if (is_string($dbTable)) {
$dbTable = new $dbTable();
}
if (!$dbTable instanceof Zend_Db_Table_Abstract) {
throw new Exception('Invalid table data gateway provided');
}
$this->_dbTable = $dbTable;
return $this;
}
public function getDbTable()
{
if (null === $this->_dbTable) {
$this->setDbTable('Application_Model_DbTable_Employee');
}
return $this->_dbTable;
}
public function fetchAll()
{
$table = $this->getDbTable();
$resultSet = $table->fetchAll($table->select()->order('EMPLOYEE_ID'));
$entries = array();
foreach ($resultSet as $row) {
$entry = new Application_Model_Employee();
$entryMessage->setEmployeeId($this->$row->EMPLOYEE_ID)
->setFirstName($row->FIRST_NAME)
->setLastName($row->LAST_NAME)
->setEmail($row->EMAIL)
->setPhoneNumber($row->PHONE_NUMBER)
->setHireDate($row->HIRE_DATE)
->setJobId($row->JOB_ID)
->setSalary($row->SALARY);
$entries[] = $entry;
}
return $entries;
}
public function save(Application_Model_Employee $employee)
{
$data = array(
'EMAIL' => $employee->getEmail(),
'FIRST_NAME' => $employee->getFirstName(),
'LAST_NAME' => $employee->getLastName(),
'PHONE_NUMBER' => $employee->getPhoneNumber(),
'HIRE_DATE' => $employee->getHireDate(),
'JOB_ID' => $employee->getJobId(),
'SALARY' => $employee->getSalary(),
);
Error you're getting is very clear, you should always read and try to understand the error message that you get, it gives you solution to most of the common problems. So always make a habit of reading and understanding the error message you get. Here,
Notice: Undefined variable: entryMessage in /var/www/Employee/application/models/EmployeeMapper.php on line 34
Notice says, undefined variable; which means that your variable $entryMessage is not defined. And the second part of the error that you are getting:
Fatal error: Call to a member function setEmployeeId() on a non-object in /var/www/Employee/application/models/EmployeeMapper.php on line 34
is very obvious since you are trying to call setEmployeeId() function from $entryMessage which has not been defined, yet you are assuming it to be an object and using it as an object.
I am assuming that $entryMessage you are using should have been $entry
These are quite simple and are not suitable to be asked in SO actually.
Once again, my suggestion to you are,
Always read what the error message says, it is what you are supposed to be using for debugging any bugs in the code
If you are new to programming you should perhaps use IDE's (netbeans,
eclipse, etc..) which actually shows the usage of variables and
function and syntax error in your code.
Always do your part of research and ask question only if not found or successful, and always show what you attempted. Others are there to help you but not to solve everything for you. :)