CodeIgniter Forums
Redirect with "pretty" urls after form submit - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived General Discussion (
+--- Thread: Redirect with "pretty" urls after form submit (/showthread.php?tid=6064)

Redirect with "pretty" urls after form submit - El Forum - 02-13-2008

[eluser]Greg Aker[/eluser]
I am tackling my first "real" project with Code Igniter. As a nice way to learn, a family member is letting me re-design/code their companies website.

I am using FreakAuth_light for the admin backend, and to change/update the site when an admin is logged in, I am using a lot of ajax in place editing, etc (learning that too =). So far, most everything is working nicely. They don't really care how it's done, so long as they can change text & add photos...they don't want to have to learn any code, and so far, there will be no need for them to use any code.

But I have run into one problem so far.

I am setting up a "projects blog" where he will be able to post new projects he's done, along with photos, etc. I have my form built, but I'm having issues getting it to redirect back to the page with "pretty urls" when the form is submitted.

Truncated form:
<?=form_open('featuredProject/projectUpdate/'. $featured->project_id);?>

So I have added the "project_id" to the url of where it is to be updated. Probably not the best way to do it, but you can see why below.

Here is my form controller:

function projectUpdate()
        $urlSegment = $this->uri->segment(3);
        $this->db->where('project_id', $urlSegment);
        $this->db->update('featuredproject', $_POST);
        $urlTitle = $this->db->query("SELECT url_title FROM featuredproject WHERE project_id = $urlSegment");
        redirect ("featuredProject/article/$urlTitle" );


When it goes back to the "featuredProject/article" page, it sets the "$urlTitle" to NULL.
I have tried putting this: redirect ("featuredProject/article/" . $urlTitle ); and redirect ('featuredProject/article/' . $urlTitle );

Here is the "article" controller.
function article()
        $data['title'] = "Featured Project";
        $title = $this->uri->segment(3);
        $query = $this->db->getwhere('featuredproject', array('url_title' => $title));
        $data['featured'] = $query->row();
        //if ( $title == '0' ) {
        $this->load->view('featuredProject/featuredProjectEntry_view', $data);

Any ideas?

Many Thanks in Advance,


Redirect with "pretty" urls after form submit - El Forum - 02-13-2008

[eluser]Chris Newton[/eluser]
The query you're pulling is an resource object, not a single piece of data. You need something like this;



if you have a column named featured, you could access it;


Review the docs on generating query results.

Also, if you're going to be doing a lot of this stuff... you might want to research using models for pulling out data, as well as active record. That way you don't have to write the same, or a similar query over and over and over.... you can just pull right from the model if it's loaded.

And on a style note, I personally avoid numbered segment variables like the plague. I prefer associative URI string name/value pairs.... helps me keep things straight in my head, and makes it easier to add / change orders of things in the URI string later if you find you have more or different data to pass. I do this so often, I created a simple uri helper that gets and sets URI data. It's nice for things like this... if (get_uri('title'){ do this }