title: CodeIgniter Redirection from form input
body: <p>I've never used a PHP framework, but I wanted to learn how to use one so I could more easily program for my company, so I chose CodeIgniter.</p>
  
  <p>I am following the code igniter tutorial for a news section so I could learn how things work - but I am having some issues/questions.</p>
  
  <p>Now, I am to the point in the tutorial that I have a form that submits and takes me to a success page. In normal PHP this is where I would just redirect the page to the view page of the news item submitted. In CodeIgniter I have a view function in my controller here</p>
  
  <pre><code>        public function view($slug = NULL)
          {
                  $data['news_item'] = $this-&gt;news_model-&gt;get_news($slug);
  
                  if (empty($data['news_item']))
                  {
                          show_404();
                  }
  
                  $data['title'] = $data['news_item']['title'];
  
                  $this-&gt;load-&gt;view('templates/header', $data);
                  $this-&gt;load-&gt;view('news/view', $data);
                  $this-&gt;load-&gt;view('templates/footer');
          }
  </code></pre>
  
  <p>I'm not sure how to get the slug from the form when it is submitted.</p>
  
  <p>Here is my create function (Basically the one that inserts the database info and redirects to <code>news/success</code>)</p>
  
  <pre><code>        public function create()
          {
              $this-&gt;load-&gt;helper('form');
              $this-&gt;load-&gt;library('form_validation');
  
              $data['title'] = 'Create a news item';
  
              $this-&gt;form_validation-&gt;set_rules('title', 'Title', 'required');
              $this-&gt;form_validation-&gt;set_rules('text', 'Text', 'required');
  
              if ($this-&gt;form_validation-&gt;run() === FALSE)
              {
                  $this-&gt;load-&gt;view('templates/header', $data);
                  $this-&gt;load-&gt;view('news/create');
                  $this-&gt;load-&gt;view('templates/footer');
  
              }
              else
              {
                  $this-&gt;news_model-&gt;set_news();
                  $this-&gt;load-&gt;view('news/success');
              }
          }
  </code></pre>
  
  <p>But I want this to redirect to the view page. To do that I need to have the slug I believe. So it should redirect to <code>news/view/$slug</code> - but I'm not sure how to do this.</p>
  
  <p>My set_news model:</p>
  
  <pre><code>        public function set_news()
          {
              $this-&gt;load-&gt;helper('url');
  
              $slug = url_title($this-&gt;input-&gt;post('title'), 'dash', TRUE);
  
              $data = array(
                  'title' =&gt; $this-&gt;input-&gt;post('title'),
                  'slug' =&gt; $slug,
                  'text' =&gt; $this-&gt;input-&gt;post('text')
              );
  
              return $this-&gt;db-&gt;insert('news', $data);
          }
  </code></pre>