Welcome Guest, Not a member yet? Register   Sign In
Creating pages
#1

[eluser]Dizza[/eluser]
Hey everyone,

I am new to codeigniter so thats probably why i ask this noobish question Tongue
The thing is that i am making a CMS, i can add manage and delete posts. But i also want to add, delete and update pages through the CMS. So i make a page @ the cms and at the frontend there is a new menu item with the new webpage.

Is there a library class for this? I searched everywhere but i cant find it.

Thanks!
#2

[eluser]harman[/eluser]
hi dizza,

first you need to understand Ci URI structure e.g

http://your-host/Controller/your_function/param1

for new post
http://your-host/Controller/posts/newpost1

here 'posts()' is function and 'newpost1' its parameter

Code:
function posts(parameter){
              //here load your model
             // here load your view
         }
read post like
Code:
<a href=" http://your-host/Controller/posts/newpost1">new post</a>
<a href=" http://your-host/Controller/posts/newpost2">new post</a>
#3

[eluser]Dizza[/eluser]
Thank you, but this is just for posts right? This is the part that i already have. I want to know how to make pages. I think i need a framework, but how can i write/create a new page? Is this with the same structure as above?
#4

[eluser]harman[/eluser]
Off course You Can Just Change Your "View"
#5

[eluser]slowgary[/eluser]
What's the difference between a post and a page? Nothing?
#6

[eluser]Caio Russo[/eluser]
hi dizza.

Let's see with I understand your need:

you have the controller:

Code:
function showPosts(){
  
  //call your model
  $allPosts = $this->posts_model->getAll();  

  //Then send that to your view:
  $this->load->view('posts',array('posts' => $allPosts));
}

and at your view you work with the array that now is called $posts.

is that?

Caio Russo
#7

[eluser]Mischievous[/eluser]
Use a controller such as this:


Code:
&lt;?php
class Page extends Controller {

function Page()
{
parent::Controller();
}
function _remap(){
$this->index();
}
function index(){
$this->load->model('page_model','page');
$page = $this->page->get($this->uri->uri_string());
if($page){
$this->load->view('page_view',$page);
} else {
$this->show_404();
}
function show_404(){
$this->load->view('error_404');
}
}
}
?&gt;

Then in your routes file inside your config directory set this up ->
Code:
$route[':any'] = 'page';

For your model run something like this:

Code:
&lt;?php
class Page_model extends Model{

function Page_model()
{
parent::Model();
}
function get($uri = NULL){
if(isset($uri)){
$this->db->where('uri', $uri);
$result = $this->db->get('pages');
if($result->num_rows() > 0){
$page = $result->result_array();
$page = $page[0]
} else {
return FALSE;
}
} else {
return FALSE;
}
}

This code isn't tested and is only for demonstration purposes only... to simply point you in the right direction.

Hope this helps you out some.
#8

[eluser]srpurdy[/eluser]
This is designed to work with freakauth so, it's just an example of admin side controls pretty straight forward. You can also write a query in the model to just display your Page Names (titles) in a css designed menu pretty easly.

This code is a bit old, but should get you in a decent direction. It's like everyone has said, it's not any different than making a blog post with info on it.

I should mention I have my model auto loaded when ci runs, so you'll need too define that either at the top of the controller or autoload it.

Controller
Code:
&lt;?php
class Pages extends Controller
{    
    function Pages()
    {
        parent::Controller();
    $this->load->helper('url');
    $this->load->helper('form');
    $this->lang->load('freakauth');
        $this->freakauth_light->check('admin');      
        $this->_container = $this->config->item('FAL_template_dir').'template_admin/container';
    }
    function index()
    {
    $heading = 'Manage Pages';
    $query = $this->admin_web->page_index();
    $page = $this->config->item('FAL_template_dir').'template_admin/pages/pages';
        $data = array(
        'query' => $query,
        'page' => $page,
        'heading' => $heading
    );
        $this->load->vars($data);
            
        $this->load->view($this->_container);
        
    }

    function editpage()
    {
    $data['heading']='Edit Page';
    $data['query'] = $this->admin_web->page_edit();
    $data['page'] = $this->config->item('FAL_template_dir').'template_admin/pages/editpage';
        $this->load->vars($data);
            
        $this->load->view($this->_container);
    
    }

    function update_page()
    {
    $this->admin_web->page_update();
    $msg = $this->lang->line('FAL_sp_updated');
    $this->db->cache_delete_all();
    flashMsg($msg);
    redirect('admin/pages');
    }

function addpage()
{
    $heading = 'Add Page';
    $page = $this->config->item('FAL_template_dir').'template_admin/pages/addpage';
        $data = array(
        'page' => $page,
        'heading' => $heading
    );
        $this->load->vars($data);
            
        $this->load->view($this->_container);
}

function insert_page()
{
$this->admin_web->page_insert();
$msg = $this->lang->line('FAL_sp_added');
$this->db->cache_delete_all();
flashMsg($msg);
redirect('admin/pages');
}

function deletepage()
{
if(isset($_POST['pid']))
    {
    $this->admin_web->page_delete();
    $msg = $this->lang->line('FAL_sp_deleted');
$this->db->cache_delete_all();
    flashMsg($msg);
    redirect('admin/pages');
    }
    else
        {
        echo "That Entry Doesen't Exist.";
        }
}
}
?&gt;

Model Functions
Code:
//Page Admin
function page_index()
{
    $this->db->orderby("pid", "asc");
    $page_index = $this->db->get('pages');
    return $page_index;
}
function page_edit()
{
    $page_edit = $this->db->getwhere('pages', array('pid' => $this->uri->segment(4)), '', '');
    return $page_edit;
}
function page_update()
{
    $this->db->where('pid', $_POST['pid']);
    $this->db->update('pages', $this->db->escape($_POST));
}
function page_insert()
{
    $this->db->insert('pages', $this->db->escape($_POST));
}
function page_delete()
{
    $this->db->delete('pages', array('pid' => $_POST['pid']));
}
#9

[eluser]Dizza[/eluser]
Hey all, thanks for the reply's!
Im going to test a few of these solutions you gave.

In the meanwhile i have found an example of what i mean with creating pages (not codeigniter):

http://www.subdreamer.com/demo/admin/pages.php < here you can create a new webpage and also edit, update and delete it.

This is what i meant with creating pages Tongue

Im sorry if im not clear enough, english is not my main language.
#10

[eluser]Caio Russo[/eluser]
Oh, you wanted for Scaffolding functions.

Caio




Theme © iAndrew 2016 - Forum software by © MyBB