CodeIgniter Forums
if page is equal to home - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: if page is equal to home (/showthread.php?tid=51223)

Pages: 1 2


if page is equal to home - El Forum - 04-25-2012

[eluser]the_unforgiven[/eluser]
Hi all,

I am wanting to know how to achieve this:

If the home page in views home.php is been displayed show something if it's not the home page then done dont show.

BUt with it not coming a database and just using view file how would this be acheived?


if page is equal to home - El Forum - 04-25-2012

[eluser]ppwalks[/eluser]
You can load other pages via functions if thats what your after for instance

[code]

function about_us() {

$this->load->view('about');

}
[code]

This will load a file called about.php in the views and will be accesible through domain such as

localhost/your_site/index.php/welcome/about_us

Is that what you was after or switching views via variable


if page is equal to home - El Forum - 04-25-2012

[eluser]the_unforgiven[/eluser]
Thats what im doing already so want to know if i do something e=like this:

Code:
<?php

if ($this->function->home_page() == true) {
echo 'this';
}
else {
do this
}
?>



if page is equal to home - El Forum - 04-25-2012

[eluser]ppwalks[/eluser]
Whats the reason for this, i'm struggling to understand your logic, if you want a process on the home page create a model and load it then call it on the view, sorry just not quite getting what your after.

Are you on about using the index.php as a controller and switching templates from there if so you would have something like this:

Controller

Code:
$data['main'] = 'home';
  $this->load->vars($data);
  $this->load->view('index');

index.php

Code:
<?php $this->load->view("main/".$main); ?>

then you can switch the pages:

So for the first example it will load home.php through $main declared in ['main']

You would then load a function from the model to do what you want on the homepage - so say you want a random feature to display you would then:

Code:
$data['your_variable_to_load_to_view'] = $this->ModelName->ModelFunction();

Then that will run any logic you want if its unique to the home page

Is this correct?


if page is equal to home - El Forum - 04-25-2012

[eluser]the_unforgiven[/eluser]
My logic is to basically saying if its the home home page show the right side navigation if its not the home page then dont show anything


if page is equal to home - El Forum - 04-25-2012

[eluser]ppwalks[/eluser]
Ahh with you now its really easy actually,

when I load the views in the index.php I switch them like I have shown you, I have created a site which I think is what you are after, on my home page I have no sidebar but on displaying products I do and I have done that using the method above:

As I load $main in the index.php it has the full width of the page and then in other pages (views) I simply use $this->load-view('view-name'); and load it as a sidebar but declare it in my controller by switching variables.

the logic above will work do you want me to provide an example?


if page is equal to home - El Forum - 04-25-2012

[eluser]the_unforgiven[/eluser]
So if i do
Code:
if($this->load->view($frontend) == 'home') {
show something
}
else {
show nothing
}

and in my controller i have the var $frontend like so:

Code:
public function index()
{
  $data['title'] = 'Page Title';
  $data['h1'] = 'Welcome';
  $data['frontend'] = 'home';
  $this->load->view('template', $data);
}



if page is equal to home - El Forum - 04-25-2012

[eluser]ppwalks[/eluser]
Have a look at this site to see if i'm right by what you want

http://www.venusstone.co.uk

the home page has no sidebar but if you click on the products tab at the top you will see that this page has one, have a look and see if thats what you are after..

If so i'll help you..


if page is equal to home - El Forum - 04-25-2012

[eluser]ppwalks[/eluser]
it is still in development



if page is equal to home - El Forum - 04-25-2012

[eluser]the_unforgiven[/eluser]
Yes exatly that....can you shed some light on how you acheived it?