Welcome Guest, Not a member yet? Register   Sign In
Wondering how to make this: /pages/view/page-title/sub-page-title/sub-sub-page-title/
#1

[eluser]Edmundas Kondrašovas[/eluser]
Hi everyone!

It has been a while since I ran into trouble developing with CodeIgniter. Smile Sorry about the title, I just couldn't think of better one. I don't know how to exactly explain the problem, but I'll do my best.

So basically I want my pages controller to load a specific page from database:

http://mypage.com/index.php/pages/view/page-title/sub-page-title/sub-sub-page-title

now, I could do this by specifying method's params:

Code:
class Pages extends Controller
{
    // Some code here...

    function view($page = NULL, $sub_page = NULL, $sub_sub_page = NULL)
    {
        // Some code here as well...
    }
}

but this would be not quite what I am looking for, since I don't know how much parent-children levels there will be. For example,
I have a few pages:

Code:
- About us
|-- Our ideas
   |-- Idea of Life
   |-- Idea of Art
|-- Experience
- Contact us

so if I wanted to reach page "Idea of Life", the URL would be something like this (assuming that titles are converted into url-friendly titles):

http://mypage.com/index.php/pages/view/About-us/Our-ideas/Idea-of-Life

or another link (About us -> Experience):

http://mypage.com/index.php/pages/view/About-us/Experience.

I hope you got the idea. If you have any ideas how to do this (or have already done something like that), share your thoughts.
Any help will be appreciated. Wink
#2

[eluser]xwero[/eluser]
Why does the url has to reflect the page hierarchy? You add the slugs: about-us, experience, ... to the database and select the item using the slug. On the page you can create a breadcrumb trail to help the visitor.
#3

[eluser]healer[/eluser]
Hi,
If you dont know how much parent child, you create table something like this below.

Code:
------------------------------------------
|page| parent |  title      |    uri     |
------------------------------------------
|   1|       0|About US     |about-us    |
|   2|       1|Our Ideas    |our-ideas   |
|   3|       2|Idea of Life |idea-of-life|
|   4|       2|Idea of Art  |idea-of-art |
------------------------------------------

then create a recursive method for query. This way is a little expensive Smile Search for better way like "Nested Tree Model".

Sorry for my english.
#4

[eluser]Edmundas Kondrašovas[/eluser]
[quote author="xwero" date="1236878168"]Why does the url has to reflect the page hierarchy? You add the slugs: about-us, experience, ... to the database and select the item using the slug. On the page you can create a breadcrumb trail to help the visitor.[/quote]
At the moment my pages table has id | parent_id | title | url_title and a few more columns and I could just use it like this:
Code:
function view($url_title = NULL)
{
    // Identify & load the page
}
but I was just wondering if there is a non-complex way of doing it. If not, I'll continue to do it like you said.
#5

[eluser]xwero[/eluser]
The reason why i asked is because adding the hierachy to the url makes it harder for the returning visitors to remember an url. When is the last time you entered an url like http://mypage.com/index.php/pages/view/A...ea-of-Life. If you search for the ideas on life a company has, the search will be something like company's ideas on life and not what about the company's ideas on life.

It's the same as naming functions. you give a function the name get_users not get_users_from_database.
#6

[eluser]Edmundas Kondrašovas[/eluser]
[quote author="xwero" date="1236879662"]The reason why i asked is because adding the hierachy to the url makes it harder for the returning visitors to remember an url. When is the last time you entered an url like http://mypage.com/index.php/pages/view/A...ea-of-Life. If you search for the ideas on life a company has, the search will be something like company's ideas on life and not what about the company's ideas on life.

It's the same as naming functions. you give a function the name get_users not get_users_from_database.[/quote]

I think you've made your point and I couldn't agree more. Now I'm starting to realize that my idea was not entirely wise and it could be frustrating to the visitors. Thank you for your opinion. Wink




Theme © iAndrew 2016 - Forum software by © MyBB