Please help me on this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Update_form::$update_model
Filename: controllers/update_form.php
Line Number: 15
Backtrace:
File: C:\xampp\htdocs\306\application\controllers\update_form.php
Line: 15
Function: _error_handler
File: C:\xampp\htdocs\306\index.php
Line: 315
Function: require_once
An uncaught Exception was encountered
Type: Error
Message: Call to a member function rest() on null
Filename: C:\xampp\htdocs\306\application\controllers\update_form.php
Line Number: 15
Backtrace:
File: C:\xampp\htdocs\306\index.php
Line: 315
Function: require_once
here is the code:
update.php
<?php
class Update extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper(array('html','form','url'));
$this->load->library('table');
$this->load->model('update_model');
}
function index()
{
$this->table->set_heading('Books Name','Author','Edit Records');
$tstyle= array(
'table_open' => '<table border="1" align="center" cellpadding="4" cellspacing ="0">'
);
$this->table->set_template($tstyle);
$answer = $this->update_model->select();
foreach ($answer as $row)
{
$link = anchor(base_url().'update_form/update_function/'.$row->id,'Edit');
$this->table->add_row($row->name,$row->author,$link);
}
echo $this->table->generate();
}
}?>
update_model.php
<?php
/**
*
*/
class Update_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
function select()
{
$this->db->select();
$this->db->from('books');
$query = $this->db->get();
return $query->result();
}
function rest($id)
{
$this->db->select();
$this->db->from('books');
$this->db->where('id',$id);
$query1= $this->db->get();
if($query1->num_rows() ==1)
{
return $query1->result();
}
}
}?>
update_form.php
<?php
class Update_form extends CI_Controller
{
function ___construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->model('update_model');
}
function update_function($id)
{
$answer = $this->update_model->rest($id);
foreach ($answer as $row)
{
echo form_open();
echo form_label('Book','book');
echo form_input('book', $row->name);
echo form_label('Author','author');
echo form_input('author', $row->author);
echo form_submit('submit','Update');
echo form_close();
}
}
}?>
You need to check line by line code which i am to add below
Controller :
Add below line on the top of the page of controller
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
**check you controller class name uppercase first letter.
**
$this->load->model('update_model');
Now update_model.php
Add : $this->db->select('*')
Try to load the model on the method or you can try to check autoload.php files..
It is showing line no 15 on update_form.php :
Create your function public in the controller.
Check or mark accepted if it works
Related
A PHP Error was encountered
Severity: Notice
Message: Undefined property: News::$News_model
Filename: controllers/News.php
Line Number: 14
Backtrace:
File: /Applications/MAMP/htdocs/workshop10/application/controllers/News.php
Line: 14
Function: _error_handler
File: /Applications/MAMP/htdocs/workshop10/index.php
Line: 315
Function: require_once
my controller:
defined('BASEPATH') OR exit('No direct script access allowed');
class News extends CI_Controller {
public function index()
{
$data['theNews'] = array("All your base are belong to us!",
"Autotune this news",
"Numa Numa!!",
$this->News_model->get_new_news()
);
$this->load->view('templates/news_header');
$this->load->view('new_items',$data);
$this->load->view('templates/news_footer');
}
}
my model:
class News_model extends CI_Model {
var $title = '';
var $content = '';
var $date = '';
public function __construct()
{
//call the Model constuctor
parent::__construct();
}
public function get_new_news()
{
return "Something Kool";
}
}
my view:
<?php
foreach ($theNews as $news_item) { ?>
<div><?php echo $news_item; ?></div>
<?php } ?>
In your controller.Use the following code.
public function index()
{
$this->load->model('News_model');//loads your model
$return = $this->News_model->get_new_news();
$data['theNews'] = array("All your base are belong to us!",
"Autotune this news",
"Numa Numa!!",
$return
);
$this->load->view('templates/news_header');
$this->load->view('new_items',$data);
$this->load->view('templates/news_footer');
}
u didnt load your model file on your controller
use this$this->load->model('News_model');
The following error is displayed:.............................................
Severity: Notice
Message: Undefined variable: groups
Filename: views/content_view.php
Line Number: 10
please can you assist me...below is the code that i have tried
below is my controller
**MY CONTROLLER**
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Delivery_controller extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('model_get');
}
public function delivery()
{
$data['groups'] = $this->model_get->getAllGroups();
$this->load->view("site_header");
$this->load->view("site_nav");
$this->load->view('login');
$this->load->view('content_view');
$this->load->view("content_video");
$this->load->view("site_footer");
}
}
?>
below is my view
**MY VIEW**
<div id="content" class="col-md-6">
<h1> Comparison</h1>
<select class="form-control">
<?php
if (is_array($groups))
{
foreach($groups as $row)
{
echo '<option value="'.$row->page.'">'.$row->page.'</option>';
}
}
?>
</select>
</div>
below is the relevant information from the model
MY MODEL
class Model_get extends CI_Model{
public function __construct()
{
parent::__construct();
}
function getAllGroups()
{
$query = $this->db->query('SELECT page FROM pageData');
return $query->result();
}
}
Try:
$this->load->view('content_view', $data);
I am trying to work through the CodeIgniter tutorial and my news pages won't output data from the foreach loop. I get the following messages:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: news
Filename: pages/index.php
Line Number: 1
and
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: pages/index.php
Line Number: 1
This is my model class:
<?php
class News_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function get_news($slug = FALSE)
{
if ($slug === FALSE)
{
$query = $this->db->get('news');
return $query->result_array();
}
$query = $this->db->get_where('news', array('slug' => $slug));
return $query->row_array();
}
public function index()
{
$data['news'] = $this->news_model->get_news();
$data['title'] = 'News archive';
$this->load->view('templates/header', $data);
$this->load->view('news/index', $data);
$this->load->view('templates/footer');
}
}
And my controller:
class News extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('news_model');
}
public function index()
{
$data['news'] = $this->news_model->get_news();
}
public function view($slug)
{
$data['news_item'] = $this->news_model->get_news($slug);
if (empty($data['news_item']))
{
show_404();
}
$data['title'] = $data['news_item']['title'];
$this->load->view('templates/header', $data);
$this->load->view('news/view', $data);
$this->load->view('templates/footer');
}
}
And the first view:
<h2><?php echo $news_item['title'] ?></h2>
<div id="main">
<?php echo $news_item['text'] ?>
</div>
<p>View article</p>
<?php endforeach ?>
and the second:
<?php
echo '<h2>'.$news_item['title'].'</h2>';
echo $news_item['text'];
I know there are other questions about the tutorial but none seemed to help me.
Thanks.
in model you have closed your class after constructor. Should be closed after all function.
Also view() is initialized twice.
I'm getting an error Undefined variable: query. I've been searching through the codeigniter forums and here for a solution but nothing seemed to work. If you can find what I'm doing wrong here I would greatly appreciate it.
Message: Undefined variable: query
Filename: views/display.php
Line Number: 3
Controller
function index() {
$this->load->model('mdl_tasks');
$data['query'] = $this->mdl_tasks->get('priority');
$this->load->view('display');
}
}
Model
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Mdl_tasks extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function get($order_by) {
$this->db->order_by($order_by);
$query = $this->db->get('tasks');
return $query;
}
}
View
<h1>Your tasks</h1>
<?php
foreach ($query->result() as $row) {
echo "<h2>".$row->title."</h2";
}
?>
you need to include $data here:
$this->load->view('display', $data);
I've heard about codeigniter couple of times so i was curious and thought why not. I took some tutorials and was very delighted to see how the framework worked.
Now i've the following problem i want to passing the data i've made in my model trough my controller and showing this in my view but i always run to the folowing error: Fatal error: Call to a member function query() on a non-object in C:\wamp\www\codeigniterTest\application\models\leden_model.php on line 9. The funny thing about this error is, when i google on this issue a lot of forum topics is about this issue but nowhere i get the right answer. my code looks like this.
codegniter version 2.03
class Leden extends CI_Controller {
function __construct(){
parent::__construct();
}
function index()
{
$this->load->model('leden_model');
$ledenModel = new Leden_model();
$data = $ledenModel->allLeden();
$this->load->view('leden_overzicht',$data);
}
}
<?php
class Leden_model extends CI_Model {
function __construct(){
parent::__construct();
}
function allLeden(){
$query = $this->db->query("SELECT * FROM leden");
foreach ($query->result_array() as $row)
{
echo $row['Naam'];
echo $row['Achternaam'];
echo $row['Email'];
}
return $query;
}
}
?>
When i'm doing the query in my controller then i'm getting the results i want, why not in my model?
my question is what am i doing wrong?
Leden_model.php
?php
class Leden_model extends CI_Model {
function __construct(){
parent::__construct();
}
function allLeden()
{
$data = array();
$this->db->select();
$query = $this->db->get('leden');
if ($query->num_rows() > 0)
{
foreach ($query->result_array() as $row)
{
$data[] = $row;
}
}
$query->free_result();
return $data;
}
Leden_controller.php
?php
class Leden extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('leden_model');
}
function index() {
$data['leden_data'] = $this->ledenModel->allLeden();
$this->load->view('leden_overzicht',$data); }
}
leden_overzicht.php
?php
if (count($leden_data))
{
foreach ($leden_data as $key => $list)
{
echo $list['Naam'] . " " . $list['Achternaam'] . " " . $list['Email'] . "";
} }
else {
echo "No data."; }
did you load database? example:
$this->load->database();