I tried to find why my $id is still NULL, but in the other project it works
please help me to find the error
An uncaught Exception was encountered
Type: Error
> Message: Call to a member function get_pengajuan() on null
Filename: .\magang\application\controllers\Surat.php
Line Number: 40
Backtrace:
File: .\magang\index.php
Line: 315
Function: require_once
Line 40 is $data['pengajuan'] = $this->MPengajuan->get_pengajuan($id);
Controller:
public function edit($id)
{
$this->load->view("header");
$this->load->view("home/user");
$this->load->view("home/admin");
$this->load->view("topbar");
$this->load->view("admin/edit_surat");
$this->load->view("footer");
$data['pengajuan'] = $this->MPengajuan->get_pengajuan($id);
}
Model:
public function get_pengajuan($id) {
$query = $this->db->query("SELECT pengajuan.* , instansi_magang.nama_instansi FROM pengajuan,instansi_magang WHERE pengajuan.id_instansi=instansi_magang.id_instansi AND id_pengajuan='$id'");
return $query->result_array();
}
View:
<?php
foreach ($pengajuan as $pengajuan_item){
echo form_open_multipart('Surat/edit/'.$pengajuan_item['id_pengajuan']);
}
?>
I suggest your error is :
You don't have to use form_open_multipart . Because there is no file to upload.
Your controller must use lowercase in your view ('surat/edit/'.$pengajuan_item['id_pengajuan'])
I got solution
that i forgot to load Model in construct with
$this->load->model('MPengajuan');
Related
I use a local XAMPP server.
PHP version 7.2.13
CodeIgniter 3.1.10
When I try to call the page posts, I get this error message:
Fatal error: Assignments can only happen to writable values in C:\xampp\htdocs\dogs\application\controllers\Posts.php on line 16
A PHP Error was encountered
Severity: Compile Error
Message: Assignments can only happen to writable values
Filename: controllers/Posts.php
Line Number: 16
Backtrace:
In Sublime line Number 16 corresponds to:
$data = ['title'] = 'Latest Posts';
My controller file Post.php:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Posts extends My_Controller {
public function index()
{
$this->load->helper('url');
$this->load->model('Post_model');
$data = ['title'] = 'Latest Posts';
$data = ['posts'] = $this->Post_model->get_posts();
$this->load->view('templates/header');
$this->load->view('posts/index', $data);
$this->load->view('templates/footer');
}
}
My view file index.php:
<h2><?= $title ?></h2>
Try this :
$data['title'] = 'Latest Posts';
$data['posts'] = $this->Post_model->get_posts();
$data['user']=$this->Post_model->get_posts();
$data['user1']=$this->Post_model->get_id();
if we will send data's like this to an array then it will work.
if you want to pass two arrays into an array then first you have to get two arrays.
like'
$result1=$this->model_name->get_data1();
$result2=$this->model_name->get_data2();
then,
$data=array();
$data['user']=$result1;
$data['user1']=$result2;
like we can pass two array into an array
and also we can access in view pages usint variable '$user' and '$user1'
class Click_image extends CI_Controller
{
function index()
{
$this->load->model('Click_image_model');
$result=$this->Click_image_model->get_data();
$array=array();
$array=json_decode(json_encode($result),true);
$data['user']=$array;
$this->load->view('Click_image',$data);
}
function get_gallery_img($id)
{
$this->load->model('Click_image_model');
$result1=$this->Click_image_model->get_name_of_gallery_id_person($id);
$data=array();
$res=$result1[0]['name'];
$res1=$result1[0]['profile_img'];
$res3=$result1[0]['category'];
$result=$this->Click_image_model->get_all_gallery_image($id);
$cat_id=$this->Click_image_model->get_category_id($res3);
print_r ($cat_id);
die();
$data=array();
$data['user']=$result;
$data['user1']=$res;
$data['user2']=$res1;
$this->load->view('Gallery_Images',$data);
}
}
I am trying to create dynamic pages in codeigniter. I m new to codeigniter.Following is my controller (Pages.php) code:
if($this->form_validation->run() == false)
{
$this->new_course();
}
else
{
$data['course_title'] = $this->input->post('pagetitle', true);
$data['course_intro'] = $this->input->post('courseintro', true);
$data['created_at'] = date('Y-m-d h:i:sa');
$data['course_slug'] = $this->seoURL($data['course_title']);
$checkPage = $this->course_model->checkPage($data);
// is page exists
if($checkPage->num_rows() > 0 )
{
customeFlash('You have already created this page', 'alert-warning', 'pages/create_course');
}
This is my Model:
public function checkPage($data)
{
return $this->db->get_where('courses',array('course_title' => $data['$data']));
}
public function add_course($data)
{
return $this->db->insert('courses', $data);
}
I am getting an error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Pages::$course_model
Filename: controllers/Pages.php
Line Number: 53
An uncaught Exception was encountered
Type: Error
Message: Call to a member function checkPage() on null
Filename: C:\xampp\htdocs\vedacg\application\controllers\Pages.php
Line Number: 53
I dont have solid programming background, can anyone help me with this?
Edit your controller 'Pages.php' using this
$this->load->model('course_model');
$checkPage = $this->course_model->checkPage($data);
First load the course_model.php in your controller
$this->load->model('course_model');
after that you can load
$checkPage = $this->course_model->checkPage($data);
Thank you all for the help... I was doing this worng in my model:
$this->db->get_where('courses', array('course_title'=>$data['$data']));
I corrected in this:
$this->db->get_where('courses', array('course_title'=>$data['course_title']));
Fetching page title from database getting error as
A PHP Error was encountered Severity: Notice Message: Trying to get
property of non-object Filename: controllers/digital_marketing.php
Line Number: 20
A PHP Error was encountered Severity: Notice Message: Trying to get
property of non-object Filename: controllers/digital_marketing.php
Line Number: 21
I am having two tables like
1.digital_marketing
2.pagetitle
In the first table i am inserting the data related to digital marketing along with digitalmarketing_name(The table will be in the following format)
digital_id description digitalmarketing_name
1 dfhbsdjbfd digital_marketing
Second Table:(pagetitle)
pagetitle_id page_title title
1 digital_marketing Digital Marketing
In this i am comparing page_title if both the page_titles match then i need to display title name but while comparing that getting an error which i have posted above.
If i am using underscore(_) in the page title it is getting that error if not it is working fine.
Controller:
class Digital_marketing extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('index_model');
$this->load->model('digitalmarketing_model');
}
public function index()
{
$data['records2']=$this->digitalmarketing_model->get_digitalmarketing();
$pageReult = $this->digitalmarketing_model->getpagetitle($this->uri->segment(1));
$data['page_title']=$pageReult->title;
$data['meta_tags']=$pageReult->meta_tags;
$data['mainpage'] = "digital-marketing";
$this->load->view('templates/template',$data);
}
Model:
function getpagetitle($id)
{
$this->db->select('P.*,D.digitalmarketing_name');
$this->db->from('pagetitle AS P');
$this->db->join('digital_marketing AS D','D.digitalmarketing_name=P.page_title','INNER');
$this->db->where(array('P.page_title'=>$id));
$q=$this->db->get();
//var_dump($this->db->last_query());
//print_r($q->num_rows());
if($q->num_rows()>0)
{
$output = $q->result();
return $output[0];
}
else
{
return false;
}
}
The pagetitle which i have inserted in digital_marketing table it is my controller name.
You can change your modal function
Controller.php
public function index()
{
$data['records2']=$this->digitalmarketing_model->get_digitalmarketing();
#echo $this->uri->segment(1); exit;
$pageReult = $this->digitalmarketing_model->getpagetitle($this->uri->segment(1));
$data['page_title']=$pageReult->title;
$data['meta_tags']=$pageReult->meta_tags;
$data['mainpage'] = "digital-marketing";
$this->load->view('templates/template',$data);
}
Modal : digitalmarketing_model.php
function getpagetitle($id) {
$this->db->select('p.*,d.digitalmarketing_name');
$this->db->from('digital_marketing AS d');
$this->db->join('pagetitle as p', 'p.page_title = d.digitalmarketing_name', 'left');
$this->db->where('p.page_title',$id);
$query = $this->db->get();
if ($query->num_rows() > 0) {
$row = $query->row();
return $row;
} else {
return false;
}
}
I hope this will helps you.
something is wrong in one of my functions. The others work fine.
The application has a MVC structure. Beginning with objects and MVC, I must ay.
Basically, I have a page (services.php) linking to:
echo"Plus d'informations...";
Function in the model page (model.php):
function get_NextServ($id)
{
global $bdd;
$id = (int)$id;
$req = $bdd->query('SELECT * FROM entreprises WHERE id= ?');
$req->execute(array($id));
return $req;
}
And the detailservices.php page:
try
{
if (isset($_GET['id']))
{
$id = intval($_GET['id']);
$billet = get_NextServ($id);
if (get_NextServ($id) < 1)
{
echo "No......";
} else
{
foreach ($billet as $data)
{
echo "<h2>" . $data['entreprise'] . "</h2>";
}
.....
I have the following errors:
Warning: Missing argument 1 for get_NextServ(), called in projects\myapp-v3\controllers\controllers.php on line 27 and defined in projects\myapp-v3\model\model.php on line 54
Notice: Undefined variable: id in projects\myapp-v3\model\model.php on line 57
Fatal error: Call to a member function execute() on a non-object in projects\myapp-v3\model\model.php on line 59
Thanks guys!
I do not want to be asking a question that has already been answered, however I have done a ton of research and I am stuck. Any help would be appreciated.
I am trying to query and add database results to OpenCart's addproduct.tpl
In the MODEL file I have:
public function units() { //function that gets database info and returns it
$unit_variables = $this->db->query("SELECT unit FROM ". DB_PREFIX ."
weight_class_description");
if (!$unit_variables) {
die(mysql_error());
}
else {
foreach ($unit_variables->rows as $temp_var) {
print_r($temp_var['unit'], true);
}
}
}
In the CONTROLLER file I have:
$this->load->model('catalog/product'); //where my function is located
$this->model_catalog_product->units();
$weight_variables = units();
if (isset($this->request->post['weight_variables'])){
$this->data['weight_variables'] = $this->request->post['weight_variables'];
}
In the VIEW I have:
<?php echo $weight_variables ?>
I get the following error:
Call to undefined function units() in /path/to/controller/file on line etc.
Note: When I print_r($temp_var); instead of returning print_R($temp_var, true) and delete these lines of code $weight_variables = units(); if (isset($this->request->post['weight_variables'])){ $this->data['weight_variables'] = $this->request->post['weight_variables'] } in the controller file my model file will display the query results on the addproduct.tpl
units() is a METHOD of your object, yet you're calling it as a standalone regular function:
$weight_variables = units();
^^^^^^^
Shouldn't it be:
$weight_variables = $this->model_catalog_product->units();
instead? And note that as-written, your method doesn't actually return anything, so $weight_variables will simply get assigned null..