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:xampphtdocsdogsapplicationcontrollersPosts.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>
Advertisement
Answer
Try this :
$data['title'] = 'Latest Posts'; $data['posts'] = $this->Post_model->get_posts();