Welcome Guest, Not a member yet? Register   Sign In
Dinamic pages from DB created in backend to be displayed in frontend
#1

[eluser]florin[/eluser]
Ok guys. I have a question for you. Let's suppose you have a site with a backend(admin panel). In backend you can add pages (that can be displayed on menu, submenu, active or inactive on site, frontend). How do you build the frontend. I mean let's asume the ADMIN creates a page in the backend pannel named "About" and set it to active and also want that to be displayed in the menu (in frontend). Since CI needs a controller(About)EX: site.com/About to display the about section of the site, how do i do that, how do i browse through the database and automatically create the controllers i need ? Or how do you manage that problem ? Cheers !
#2

[eluser]InsiteFX[/eluser]
See the News Tutorial in the CodeIgniter Users Guide.
#3

[eluser]florin[/eluser]
That's not the answer that i'm hoping for, seams that you didnt understood my question or you read only the title. Let's asume that we have an admin panel and there we have ADD PAGES (main, subpages,etc) tat can be setted to ACTIVE and added on the menu. (EX: we add the page Contact as a MAIN PAGE, set it to ACTIVE and set it to SHOW IN THE MENU). How can we construct the frontend ? Ok, we can browse the database and then construct the menu view (loop trough the DB and if the page is active add the page on the menu) but then we'll have the menu links broken, in this case site.com/Contact because the "Contact" controller is not there. As you can see we are pointing to the "Contact" controller wich dont exist. How do I automatically create the controller in frontend or how do we manage that task. I hope i was clear enough this time...Tank's all !
#4

[eluser]InsiteFX[/eluser]
I did not miss read your topic title.

You neeed a page controller that handles all your pages, if you read the above tutorial it shows you how to create the news for pages.

As far as the menu you store the menu link with the page data in the database as a url and uri link.
#5

[eluser]Otemu[/eluser]
Hi,

You could try such an approach like this:

1. Create generic layouts for each page such as main pages, article pages, etc.
2. Create reusable modules that you can drop and place on any page, header, footer, sidebars, widgets, etc.
3. On the back-end when creating pages give the option to select template to use such as mainpage template, singlepage template and maybe you could give the option to add modules to the page.
4. When user goes to mysite.com/contactus check if the page exists in database and active, load appropriate view such as contactus page, load all data into this view and display selected modules.

Pseudocode:

Controller:
Code:
<?php
class Mainpage extends CI_Controller {

    public function home($getPage)
    {
       ......go to model see if page exists
       ......model returns results
       ......load view depending on template selected on backend
       ......all results returned to view
    }
}
?>

Generic View for main pages:
Code:
<html>
<head>
<title>....load title from back-end</title>
</head>
<body>
        ....load header
<div id="webPage">...load page content from back-end</div>
        <div id="sideBar">...load modules</div>
        .....load footer
&lt;/body&gt;
&lt;/html&gt;


This way you can easily add pages to the database and the generic view created will handle it, you can also easily change layout depending on template loaded. Of course this not a well detailed explanation but hope it helps you get started.



#6

[eluser]florin[/eluser]
It takes the pagename as parameter like site.com/pages/contact...i see now Tks alot !
#7

[eluser]florin[/eluser]
Tks alot Otemu ! I apreciate your very nice and rapid replay




Theme © iAndrew 2016 - Forum software by © MyBB