(02-08-2016, 05:00 AM)InsiteFX Wrote: Most of the problems are because they do not add the routes to the tutorial.
Hi,
(i am not english native sorry for my english)
I have this error
Parse error: syntax error, unexpected 'public' (T_PUBLIC) in
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\application\models\News_model.php on line
10
A PHP Error was encountered
Severity: Parsing Error
Message: syntax error, unexpected 'public' (T_PUBLIC)
Filename: models/News_model.php
Line Number: 10
Backtrace:
Is my route bad ??
This is my News_model.php
<?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();
}
My News.php
<?php
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();
$data['title'] = 'News archive';
$this->load->view('templates/header', $data);
$this->load->view('news/index', $data);
$this->load->view('templates/footer');
}
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');
}
}
My view.php
<?php
echo '<h2>'.$news_item['title'].'</h2>';
echo $news_item['text'];
My index.php
<h2><?php echo $title; ?></h2>
<?php foreach ($news as $news_item): ?>
<h3><?php echo $news_item['title']; ?></h3>
<div class="main">
<?php echo $news_item['text']; ?>
</div>
<p><a href="<?php echo site_url('news/'.$news_item['slug']); ?>">View article</a></p>
<?php endforeach; ?>
My routes.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
?>
The pages example run ok, aftaer that I set the rules for news before pages, but news do no run give me that parse error.
In database.php, I add a final line becasue my Mysql has a 3308 port
$db['default']['port'] = 3308;
Windows 7 with EASYPHP DEVSERVER version :
16.1.1
PHP 5.6.19 x86 Mysql 5.7
My paths
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\application\models
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\application\controllers
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\application\models
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\application\views
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\application\views\news
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\application\views\templates
If someone see something wrong please tell me
Thanks!
Greetings!
Jose