Welcome Guest, Not a member yet? Register   Sign In
url_title() HELP
#1

[eluser]HSKrustofsky[/eluser]
I know this has been posted a bunch of times, but still can't seem to get the grasp of it. No matter what I do, it doesn't seem to work properly.

I am trying to convert:
index.php/blog/5

To:
index.php/blog/this_is_my_blog

I saw that the best way to achieve this is with using url_title(). Well, this is how I am trying to us it, and it doesn't work:

Code:
<?= anchor('idnex.php/blog/' . $row->id . url_title($row->title, 'underscore', true), '' . $row->title); ?>

The link works but it adds the title after the ID number(which I kind of figured would happen).

Anything else I try just kills the link, or the page.

Any suggestions?
#2

[eluser]Bas Vermeulen[/eluser]
You still have $row->id in your link, try:

Code:
<?= anchor('index.php/blog/' . url_title($row->title, 'underscore', true).'', $row->title); ?>
#3

[eluser]HSKrustofsky[/eluser]
Tried that, but it doesnt really link to anything. With no ID, it doesn't know where to go...
#4

[eluser]Bas Vermeulen[/eluser]
Hmm weird, this example works for me. Echo of $row->title shows the title?
#5

[eluser]HSKrustofsky[/eluser]
It shows the title, but it links to the title and not the ID. So when you click the link, it's got nothing to reference to, but the title.
#6

[eluser]fraserk[/eluser]
How about this.

Code:
$title = $row->title;
$url_title = url_title($title);


Then

Code:
<?= anchor('idnex.php/blog/' . $row->id .$url_title, . $row->title); ?>
#7

[eluser]cideveloper[/eluser]
your problem is that your index function in the blog controller is expecting an id not the title.

If you use what Bas said

Code:
<?= anchor('index.php/blog/' . url_title($row->title, 'underscore', true).'', $row->title); ?>

you should get a link that looks like this

Code:
<a href="http://localhost/index.php/blog/blog_article_title">blog_article_title</a>

your blog function should look something like this

Code:
function index($title=''){
$this->db->where('field_in_db_with_title', $title);
$this->db->get('blog_article_table');
//other code
}


Please show us your index function in the blog controller.
#8

[eluser]Bas Vermeulen[/eluser]
Ah yes cideveloper is right, I just thought your <a> function didn't work ;p




Theme © iAndrew 2016 - Forum software by © MyBB