Welcome Guest, Not a member yet? Register   Sign In
Wildcard Url
#1

[eluser]Unknown[/eluser]
Hi i am trying to add more parameters to my rewrittten urls, suppose i have.

Code:
example.com/books/book-name
book-name is the slug.

What do i need to do to add an extra segment to the url also keeping the slug i.e.
Code:
example.com/books/book-name/chapter-1

could even be (example.com/book-name/chapter-1)

1 would be another query parameter. Because book-name isnt a view, how do I keep the slug in the url always with different book names and append another query parameter?

I am totally new to codeigniter.
Any help would be appreciated thanks.
#2

[eluser]Tpojka[/eluser]
Rewritten URLs are minor task here.
You have to make controller that would be well coded for wanted achievment.
I will just make starting point for you because it is not small task, but I will try to show how would I do that.
Add this line to application/config/routes.php
Code:
$route['books/(:any)/(:any)'] = "books/bookName/$1/$2";
Than make this controller application/controllers/books.php
Code:
<?php if (!defined('BASEPATH')) die();
class Books extends CI_Controller

{
   public function __construct()
   {
      parent::__construct();
   }

   public function bookName($name = 'some-name', $chapter = 'some-cahpter1')
   {
      echo strtolower($this->uri->segment(1)) . '/' . $this->uri->segment(2) . '/' . $this->uri->segment(3);
   }

}

/* End of file Books.php */
/* Location: ./application/controllers/Books.php */

Now, navigate to it. You should see uri string (I have echoed it ont that way on purpose) in page content.
Now change arguments in url in your open browser (except 'books' segment) and you will see how is content changed.
Plan is next: you need to check every argument you are using with query that will check DB for particular book/chapter or any other property you made your DB organization with.
Knowing controllers and models is a must so start with user guide.
You will need to study this part of user guide too.
If you are familiar with (OOP) PHP, this could be a good starting point for solving that task.
If you stuck somewhere, ask. Good luck.




Theme © iAndrew 2016 - Forum software by © MyBB