Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4236250
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:36:47+00:00 2026-05-21T02:36:47+00:00

Update: I have tried Sheldon’s code below but I have struck a couple of

  • 0

Update:

I have tried Sheldon’s code below but I have struck a couple of issues:

  1. When using the line $this->load->view($page->template, array('content' => $page->content), TRUE);Unable to load the requested file .php but if I change it to $page->content it works fine.

  2. When I place the index functions into my other controllers it still loads the default home controller despite what the uri segment is set to. How do I adjust the model for this to work?

Original Question:

I have a template.php file which houses my main site structure. Suppose I have a page called ‘home’. I would like to set the $title and the $content data from the database.

I have set a view for each page and also a controller. I have tried:

$this->cms_pages->name;

This produces nothing. I know I need to get the URI segment but because I am using /$sales->name I am unsure if I have to change it to $sales->id for this to work. I would like to get it by the name. Best practices are also important.

Is there a way that I could do something like: $this->cms_pages->id->1->name?

Model

function getCMSPages() {

    $query = $this->db->get('pages');
    if($query->num_rows() > 0) return $query->result();
}

Template

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {

public function index()
{
$data['cms_pages'] = $this->navigation_model->getCMSPages();
$data['title'] = 'Ccho';
$data['content'] = $this->load->view('home', NULL, TRUE);
$this->load->view('template', $data);
}
}

Template

 $stylesheetCSS = array('href' => 'includes/css/style.css', 'rel' => 'stylesheet',   'type' => 'text/css', 'media' => 'print');

echo doctype('html5');
?>
<head>
 <title>Housemovers : <?php echo $title ?></title>
  <?php echo link_tag($stylesheetCSS);?>
   </head>
 <body>
<div id ="wrapper">
<header>
<p>content</p>
</header>
<nav>
    <ul>
    <?php if($this->session->userdata('logged_in')): ?>
        <li><?php echo anchor('#','Edit Pages');?>
        <?php if(is_array($cms_pages)): ?>
                <ul>
                    <?php foreach($cms_pages as $page): ?>
                    <li><a href="<?=$page->title?>"><?= $page->title?></a></li>
                    <?php endforeach; ?>
                </ul>
            <?php endif; ?>
            </li>
        <li><?php echo anchor('#','Gallery');?>
        <ul>
            <li><?php echo anchor('admin/addgallery','Add Gallery');?></li>
            <li><?php echo anchor('admin/uploadimage','Upload Image');?>
            </li>
            <li><?php echo anchor('#','Delete Gallery');?></li>
        </ul>
        </li>
        <li><?php echo anchor('#','Sales');?>
        <ul>
            <li><?php echo anchor('admin/addsale','Add Sale');?></li>
            <li><?php echo anchor('#','Edit Sale');?>
            <?php if(is_array($sales_pages)): ?>
                <ul>
                    <?php foreach($sales_pages as $sale): ?>
                    <li><a href="editsale/index/<?=$sale->id?>"><?= $sale->name?></a></li>
                    <?php endforeach; ?>
                </ul>
            <?php endif; ?>
            </li>

            <li><?php echo anchor('#','Delete Sale');?></li>
            <li><?php echo anchor('admin/home/logout','Log Out');?></li>
        </ul>
        </li>
    <?php else: ?>
    <ul>
    <li><?php echo anchor('home','Home');?></li>
    <li><?php echo anchor('about','About Us');?></li>
    <li><?php echo anchor('gallery','Gallery');?></li>
    <li><?php echo anchor('testimonials', 'Testimonials');?></li>
    <li><?php echo anchor('sales','Sales');?></li>
    <li><?php echo anchor('contact','Contact Us');?></li>
    </ul>
    <?php endif; ?>
    </ul>
</nav>
 <section id="content">
    <h1><?= $title ?></h1>

    <p><?= $content ?></p>

</section>

<footer>&copy; Houses LTD <?php echo date('Y');?></footer>
</div> <!-- Wrapper Close -->

</body>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:36:47+00:00Added an answer on May 21, 2026 at 2:36 am

    As @davzie said;

    Model

    function getCMSPage($page_name = '') {
    
        if(!$page_name) $page_name= 'home'; // home be default.    
        $this->db->where('name', $page_name);
        $query = $this->db->get('pages', 1);
        if($query->num_rows() == 1) return $query->row();
    }
    

    Controller

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Home extends CI_Controller {
    
    public function index()
    {
    $page = $this->navigation_model->getCMSPage($this-uri->segment(1)); // pretend the first segment in your URI is the page you want.
    $data['cms_pages'] = $this->navigation_model->getCMSPages();
    $data['title'] = $page->name;
    $data['content'] = $this->load->view($page->template, array('content' => $page->content), TRUE);
    $this->load->view('template', $data);
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update : I have tried using fuslogvw.exe to get logs. But what exactly am
I have tried the following MySQL update but it only sets the first field
UPDATE I tried using the internal wordpress rewrite. What I have to do is
UPDATE - I have fixed some mistakes in the code below and the images
Update I have just tried Pinning my site to the Taskbar again (after removing
I have tried to get some information from W3C regarding the update of an
I have tried to install gem draper and it asked me to update my
I have also tried .('refresh') and .page() to no avail. The text-box updates but
UPDATE I have updated my code in response to @MichaelRushton comments. I am now
**Updated: (See below)**I have been looking around for couple of days and can't find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.