Welcome Guest, Not a member yet? Register   Sign In
preg_match(): Compilation failed
#1

Hello I am new to codeigniter forum. And I am also a new user of code igniter MVC platform. Last couple of day I have encountered a problem.. Is there anyone can help me to resolve this.


A PHP Error was encountered
Severity: Warning

Message: preg_match(): Compilation failed: missing ) at offset 16

Filename: core/Router.php

Line Number: 399

Backtrace:

File: C:\xampp\htdocs\ciblog\index.php
Line: 315
Function: require_once
Reply
#2

(This post was last modified: 01-25-2020, 11:37 AM by jreklund.)

Have you done any modifications to your /system folder and/or installed something new?
Have you added a new route in config/routes.php? That somehow breaks free and breaks your core/Router.php.
Reply
#3

(This post was last modified: 01-25-2020, 11:39 AM by jreklund.)

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

$route['posts/create'] = 'posts/create';
$route['(posts/(:any)'] = 'posts/view/$1';
$route['posts'] = 'posts/index';
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

This is the code. How can I fix this
Reply
#4

I'm guessing it's this guys fault: $route['(posts/(:any)'] = 'posts/view/$1';
It should be: $route['posts/(:any)'] = 'posts/view/$1';

If it still dosen't work. What version of CodeIgniter do you use? And have you done any modifications to the system folder?
Reply
#5

I found a problem when go for edit a post.. Then wrongly redirect to http://localhost/ciblog/posts/posts/edit/Post-One rather http://localhost/ciblog/posts/edit/Post-One. That's why it is found that 404 Page Not Found. It may be caused by wrong link.. Someone please help to check following codes.

edit.php

<h2><?= $title; ?> </h2>

<?php echo validation_errors(); ?>

<?php echo form_open('posts/update'); ?>

<div class="form-group">
<label>Title</label>
<input type="text" class="form-control" name="title" placeholder="Add Title" value="<?php echo $post['title']; ?>">
</div>
<div class="form-group">
<label>Body</label>
<textarea class="form-control" name="body" placeholder="Add Body"><?php echo $post['body']; ?></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>

----------------------------------------------------------------
view.php

<h2><?php echo $post['title']; ?></h2>
<small class="post-date">Posted on: <?php echo $post['created at']; ?> </small><br>
<div class="post-body">
<?php echo $post['body']; ?>
</div>

<hr>
<a class="btn btn-primary pull-left" href="posts/edit/<?php echo $post['slug']; ?>">Edit</a>
<?php echo form_open('/posts/delete/'.$post['id']); ?>
<input type="submit" value="Delete" class="btn btn-danger">

</form>
-------------------------------------------------
Post_model.php

<?php
class Post_model extends CI_Model {

public function __construct()
{
$this->load->database();
}
public function get_posts($slug = FALSE){
if ($slug === FALSE) {
$this->db->order_by('id', 'DESC');
$query = $this->db->get('posts');
return $query->result_array();
}

$query = $this->db->get_where('posts', array('slug'=> $slug));
return $query->row_array();
}
public function create_post(){
$slug = url_title($this->input->post('title'));

$data = array(
'title' => $this->input->post('title'),
'slug' => $slug,
'body' => $this->input->post('body')
);
return $this->db->insert('posts', $data);
}

public function delete_post($id){
$this->db->where('id', $id);
$this->db->delete('posts');
return true;
}
}

----------------------------------------------------------
Post Controller
Post.php

<?php
class Posts extends CI_Controller{
public function index(){

$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');
}

public function view($slug = NULL){
$data['post'] = $this->post_model->get_posts($slug);
if(empty($data['post'])){
show_404();
}
$data['title'] = $data['post']['title'];

$this->load->view('templates/header');
$this->load->view('posts/view', $data);
$this->load->view('templates/footer');
}

public function create(){
$data['title'] = 'Create Post' ;
$this->form_validation->set_rules('title','Title','required');
$this->form_validation->set_rules('body','Body','required');
if ($this->form_validation->run() === FALSE){
$this->load->view('templates/header');
$this->load->view('posts/create', $data);
$this->load->view('templates/footer');
} else {
$this->post_model->create_post();
redirect('posts');
}
}
public function delete($id){
$this->post_model->delete_post($id);
redirect('posts');
}
public function edit($slug){
$data['post'] = $this->post_model->get_posts($slug);
if(empty($data['post'])){
show_404();
}
$data['title'] = 'Edit Post';

$this->load->view('templates/header');
$this->load->view('posts/edit', $data);
$this->load->view('templates/footer');
}
public function update(){
echo 'Submitted';
}
}

--------------------------------------------------------------------------------
Reply




Theme © iAndrew 2016 - Forum software by © MyBB