Welcome Guest, Not a member yet? Register   Sign In
Problem with Tutorial, part III - "Create News form"...
#1

[eluser]Matteo[/eluser]
Not sure what is happening, but after following the tutorial, all I get is a blank page following the 3rd part of the tutorial. My code is as follows:

MODEL CODE (3.0)
Code:
<?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();
}

public function set_news()
{
  $this->load->helper('url');
  
  $slug = url_title($this->input->post('title'), 'dash', TRUE);
  
  $data = array(
   'title' => $this->input->post('title'),
   'slug' => $slug,
   'text' => $this->input->post('text')
  );
  
  return $this->db->insert('news', $data);
}
}

VIEW CODE (3.0)
Code:
<h2>Create a news item</h2>

&lt;?php echo validation_errors(); ?&gt;

&lt;?php echo form_open('news/create') ?&gt;

<label for="title">Title</label>
&lt;input type="input" name="title" /&gt;&lt;br />

<label for="text">Text</label>
&lt;textarea name="text"&gt;&lt;/textarea><br />

&lt;input type="submit" name="submit" value="Create news item" /&gt;

&lt;/form&gt;

CONTROLLER CODE (3.0)
Code:
&lt;?php
class News extends CI_Controller {

public function __construct()
{
  parent::__construct();
  $this->load->model('news_model');
}

public function index()
{
  $data['news'] = $this->news_model->get_news();
  $data['title'] = 'News archive';

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

public function view($slug)
{
  $data['news'] = $this->news_model->get_news($slug);
  
  if (empty($data['news_item']))
  {
   show_404();
  }

  $data['title'] = $data['news_item']['title'];

  $this->load->view('header', $data);
  $this->load->view('news/view', $data);
  $this->load->view('footer');
}
public function create()
{
  $this->load->helper('form');
  $this->load->library('form_validation');
  
  $data['title'] = 'Create a news item';
  
  $this->form_validation->set_rules('title', 'Title', 'required');
  $this->form_validation->set_rules('text', 'text', 'required');
  
  if ($this->form_validation->run() === FALSE)
  {
   $this->load->view('templates/header', $data);
   $this->load->view('news/create');
   $this->load->view('templates/footer');
  
  }
  else
  {
   $this->news_model->set_news();
   $this->load->view('news/success');
  }
}
}

Again, all the browser output is a blank screen. Viewing the source code for the browser shows an empty render. Any ideas?

Also, I am now getting the same problem with the second part of the 2nd tutorial. The "view article" links also bring up a blank page in the browser; no errors, no 404 re-directs, etc. Just a blank page.

Since the code for the 3rd tutorial includes the 2.2 code, I didn't recreate it here.

Please help...
#2

[eluser]Unknown[/eluser]
Hi,

I had the same problem and i was able to fix the problem when i changed the base URL.

Earlier to the problem i had my base URL as http://localhost

but i changed the baseURL in config.php to http://localhost/CodeIgniter.

[$config['base_url'] = 'http://localhost/CodeIgniter/';]


CodeIgniter is the name of the folder/project inside the server.

If you notice after you click on Create News item, the URL changes and your project name will disappear. Adding the project/folder name solves the problem.

Hopefully this helps to solve your problem. :-)

Best Regards,
Prabesh Bhaskaran.
#3

[eluser]Unknown[/eluser]
Hi All
Could I also ask a question on this topic.

I am pretty sure I have followed this beginner tutorial exactly but each time I submit my form it goes to the wrong url. What it seems to be doing is appending the form action value (news/create) onto the end of the existing URL rather than overwriting it.

Has anyone got any suggestions on this for a newb?

Many Thanks

EDIT: Ahh i found the solution elsewhere - it was an issue with my base url http://stackoverflow.com/questions/88728...t-not-work




Theme © iAndrew 2016 - Forum software by © MyBB