I am new in codeigniter framework of PHP. I want display the news headlines in scrolling marquee I tried this
view page
<marquee bgcolor="black"><font color="white">
<?php
foreach($news as $row)
{
$heading=$row->st_head;
echo $heading;
}
?>
</font ></marquee>
controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Headlines extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('Headlines_model');
}
public function index()
{
$where_cond = "flg_is_active = 1";
$select_cond = "st_head,in_news_id";
$data['news'] = $this->Headlines_model->select_records($where_cond,$select_cond );
$this->load->view('Headlines',$data);
}
}
*****Model **************
<?php
class Headlines_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
$this->table_name = 'tbl_news';
}
public function select_records($where=NULL,$select=NULL,$jointable=NULL,$joinkey=NULL,$per_page=NULL,$limit=NULL,$order_by=NULL, $count = false)
{
if($where!=NULL)
$this->db->where($where);
if($select!=NULL)
$this->db->select($select);
if($jointable!=NULL && $joinkey!=NULL)
$this->db->join($jointable, $joinkey);
if($limit!=NULL || $per_page!=NULL)
$this->db->limit($limit, $per_page);
if($order_by!=NULL)
$this->db->order_by($order_by);
$query = $this->db->get($this->table_name);
if($count==true)
{
return $query->num_rows();
}
else
{
return $query->result();
}
}
}
?>
if I display without marquee the show the data properly. But when I use marquee then it gives following error
PHP Error was encountered
Severity: Notice
Message: Undefined variable: news
Filename: views/Headlines.php
Line Number: 2
Related
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class checklist extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->model('checklist_model');
}
public function index()
{
$data['check_list'] = $this->checklist_model->get_all_details();
$this->load->view('show_checklist', $data);
}
public function form_dropdown()
{
$this->load->view('insert_checklist');
}
public function data_submitted()
{
$data = array('dropdown_single' => $this->input->post('Technology'));
$this->load->model('checklist_model');
$this->checklist_model->insert_in_db($data);
$this->load->model("checklist_model");
$result = $this->checklist_model->read_from_db($data);
$data['result'] = $result[0];
$this->load->view('insert_checklist', $data);
}
public function add_form()
{
$this->load->view('insert_checklist');
}
public function edit()
{
$id = $this->uri->segment(3);
$data['details'] = $this->checklist_model->getById($id);
$this->load->view('edit', $data);
}
public function delete($id)
{
$this->checklist_model->delete_a_detail($id);
$this->index();
}
public function insert_new_details()
{
$udata['technology_name'] = $this->input->post('technology_name');
$udata['questions'] = $this->input->post('questions');
$udata['status'] = $this->input->post('status');
$udata['comments'] = $this->input->post('comments');
$res = $this->checklist_model->insert_details_to_db($udata);
if($res)
{
header('location:'.base_url()."/index.php/checklist/".$this->index());
}
}
public function update()
{
$mdata['technology_name']=$_POST['technology_name'];
$mdata['questions']=$_POST['questions'];
$mdata['status']=$_POST['status'];
$mdata['comments']=$_POST['comments'];
$res=$this->checklist_model->update_info($mdata, $_POST['id']);
if($res)
{
header('location:'.base_url()."/index.php/checklist/".$this->index());
}
}
}
?>
it means you call for an array variable's index 'question', and that index does not exist in that array. Maybe in function update(), $_POST['question']. Not sure. You should provide the full error msg, like file and line.
Also: the view if that's the case. And make this sound more like a question.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class dept_officer extends CI_Model{
function __construct()
{
parent::__construct();
}
function get_sponsorship_list()
{
$this->db->from('tbl_donor');
$this->db->join('tbl_sponsorship', 'tbl_donor.DonorId = tbl_sponsor.DonorId');
$query = $this->db->get();
return $query->result();
}
function get_programme_list()
{
$this->db->from('tbl_program');
$this->db->join('tbl_sponsorship', 'tbl_program.SponsorshipId = tbl_sponsor.ponsorshipId');
$query = $this->db->get();
return $query->result();
}
function get_child_list()
{
$this->db->from('tbl_child');
$this->db->join('tbl_family', 'tbl_child.FamilyID = tbl_family.FamilyID');
$this->db->join('tbl_school', 'tbl_child.SchoolID = tbl_school.SchoolID');
$query = $this->db->get();
return $query->result();
}
function get_crpo_list()
{
$this->db->from('tbl_crpo');
$this->db->join('tbl_district', 'tbl_ds_division.DistrictI = tbl_district.DistrictId');
$this->db->join('tbl_dsdivision', 'tbl_crpo.ds_divisionId = tbl_ds_division.ds_divisionId');
$query = $this->db->get();
return $query->result();
}
}
?>
I've created this class to contains all the queries to display list of different users in the system. i get a compile error saying cannot redeclare class dept_officer even though i haven't tried to declare any classes.
The above is the code for the model in codeigniter
I am trying to learn code igniter and creating helper files. I have this as my functions_helper.php file located in my applications/helpers folder:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function __construct()
{
parent::__construct();
$this->load->model('user','',TRUE);
}
if (!function_exists('check_status')){
function check_status()
{
$CI = & get_instance();
$result=$CI->user->get_status(); //this is line 14!!
if($result)
{
$status_array=array();
foreach($result as $row)
{
$status_array=array(
'source' => $row->status,
'current' => $row->id
);
if ($status_array['current'] == 1) {
$status_array['current'] = "Live";
} else {
$status_array['current'] = "Amazon is Down";
}
$CI->session->set_userdata('status',$status_array);
}
return TRUE;
}
else
{
return false;
}
} // END OF CHECK_STATUS FUNCTION
}
From everything i can find, I am doing it correctly, yet I am getting this error:
PHP Fatal error: Call to a member function get_status() on a non-object in function_helper.php on line 14. exactly what am i doing wrong? Is this the best way to call a function? Ultimately I am trying to get information returned from a db query.
My get_status function is:
//FUNCTION TO SEE THE STATUS OF AMAZON
function get_status() {
$query = $this->db->query("select * from amz where active = 1");
if($query->num_rows()==1) {
return $query->row_array();
}else {
return false;
}
} //END OF GET_STATUS FUNCTION
Remove this code
function __construct()
{
parent::__construct();
$this->load->model('user','',TRUE);
}
There is no OO in helper files. You do not have a class -__construct() are used to initialize classes.
Then move
$this->load->model('user','',TRUE); to the check_status function
$CI =& get_instance();
$CI->load->model('user','','TRUE');
I am getting error when calling the model from controller.
Error:- SCREAM: Error suppression ignored for
( ! ) Fatal error: Class 'Redirection_model' not found in C:\wamp\www\redirect\system\core\Loader.php on line 30
My controller redirection.php
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class redirection extends CI_Controller {
function __construct()
{
parent::__construct();
//$this->layout->setLayout('layouts/main');
}
public function redirection_url()
{
if($_GET){
$get_array = $_GET;
$targetId = $get_array['tagid'];
$this->load->model('redirection_model', 'redirection');
$dynamicurl = $this->redirection->getDynamicUrl($targetId);
if($dynamicurl){
$url=$dynamicurl['url'];
redirect($url,'refresh');
}
else{
echo "Invalid Request";
}
}
else{
echo "please pass the tagid";
// $this->layout->view('redirection/redirection_url');
}
}
}
redirection_model.php
<?
class redirection_model extends CI_Model {
function __construct()
{
parent::__construct();
}
function getDynamicUrl($targetId){
$dynamicUrl= array();
$query = $this->db->get_where('dynamic_url', array('tagid' => $targetId))->row();
if($query){
$dynamicUrl['url'] = $query->url;
$dynamicUrl['userid'] = $query->userid;
return $dynamicUrl;
}
else{
return false;
}
}
}
?>
you have not linked your view in controller, insert it.
And Also check you route file which is in your config folder, there you have to make entry for for your functions and route for view.
Here it is my code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->database(); /* This function it's used to connect to database */
$this->load->model('User','user'); /* This call the model to retrieve data from db */
}
public function index()
{
if(!file_exists('application/views/_login.php'))
{
show_404();
}
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<h4 style="text-align:center;">','</h4>');
$this->form_validation->set_rules('username','username','trim|required|xss_clean');
$this->form_validation->set_rules('password','password','trim|required|xss_clean|callback_pass_check');
if($this->form_validation->run() == FALSE)
{
$data['title'] = "User Access";
$data['author'] = "Salvatore Mazzarino";
$this->load->view('templates/_header',$data);
$this->load->view('_login',$data);
$this->load->view('templates/_footer',$data);
}
else
{
redirect('home', 'refresh');
}
}
public function pass_check($pass)
{
$result = $this->user->find_user($this->input->post('username'),$pass);
if($result == 1)
{
$session_array = array();
foreach ($result as $row)
{
$session_array = array('id'=> $row->id,'username'=> $row->username); /* Create a session passing user data */
$this->session->set_userdata('logged_in',$session_array);
}
return TRUE;
}
else
{
$this->form_validation->set_message('pass_check',"Invalid username or password!</br>Try again, please!");
return FALSE;
}
}
}
Here it is the line
$this->session->set_userdata('logged_in',$session_array);
that cause the error:
PHP Fatal error: Call to a member function set_userdata() on a non-object
Someone could say me the reason?
Make sure the session library is loaded.
You can add it in application/config/autoload.php to be loaded automatically.
http://ellislab.com/codeigniter/user_guide/libraries/sessions.html