controllers/News.php |
The error message you got, is caused by a missing semi-colon at the end of line 8.
Also, if you load a model, it should be in lower case, although the file name starts with a capital letter.
(04-29-2019, 08:08 AM)ciadmin Wrote: You deleted the vurly brace at the end of the index method, before line 18. <<?php defined('BASEPATH') OR exit('No direct script access allowed'); 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(); } Do you mean the line which I high lighten in bold. Remember I am new to code igniter.
(04-29-2019, 10:45 AM)shewolf255 Wrote:(04-29-2019, 08:08 AM)ciadmin Wrote: You deleted the vurly brace at the end of the index method, before line 18.
(04-29-2019, 08:52 AM)Wouter60 Wrote: The error message you got, is caused by a missing semi-colon at the end of line 8. Hi Wouter60. I am still getting the following errors. An uncaught Exception was encountered Type: ParseError Message: syntax error, unexpected 'public' (T_PUBLIC) Filename: C:\wamp64\www\aircomp.co.za\application\controllers\News.php Line Number: 18 Backtrace: File: C:\wamp64\www\aircomp.co.za\index.php Line: 315 Function: require_once And here is my code from the controllers/News.php <?php defined('BASEPATH') OR exit('No direct script access allowed'); class News extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('News_model'); $this->load->helper('url_helper'); } public function index() { $data['news'] = $this->news_model->get_news(); public function view($slug = NULL) { $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'); } }
You have two lines with braces in your model code.
The first brace closes the constructor method. The second brace closes the class definition, leaving the remaining methods as functions and not class methods. It sounds like you are new to PHP and not just CodeIgniter. You need to learn/review O-O practices in PHP.
(04-29-2019, 11:06 AM)ciadmin Wrote: You have two lines with braces in your model code. You are correct, and you learn through your mistakes. Now I have this question to asked you. 1) Do the model's need to be in capital letters, model/News.php ? I want to build my very own cms for our business to record, index our products and management the website. And record the traffic to the website.
Also please use the Start new topic and use the editor with code tags.
Makes it a lot easier to read your code. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |