Welcome Guest, Not a member yet? Register   Sign In
Want show home page content only on home page
#1

[eluser]the_unforgiven[/eluser]
HI All,

I'm new to the forums and codeigniter so please be gentle.

I have started a project (for testing/learning purposes)
and I have an admin system in which i can add all the info and all is working fine but i have a small issue. The home page content shows on every page and i wish to know what would be the correct code to only show this on the home page or index page.
I have tried these: But no joy:
Code:
if (isset($this->request->get['route']) && $this->request->get['path'] == 'welcome'){
//Code here
}
also tried a switch case etc but still no joy.

Or yes I am using the shopping cart class and backend pro by Kaimonokago

If anyone can point me in the right direction it would be very much appreciated, if you need to see any more code let me know what you want to see.
#2

[eluser]the_unforgiven[/eluser]
Anyone willing to help me please?
#3

[eluser]TWP Marketing[/eluser]
Use multiple view files and only send the data necessary for each view.

If I had to guess, you may only have a single view file and are trying to use it for everything?

If you are not already doing so, design your pages using header,content and footer sections (views).
Header and footer views tend to be static while the content view(s) change as dictated by site design and flow. This leads to a template style of design, which you may find useful.

I know this is very general, but your question is very broad. Please look through the list of tutorials on the wiki: http://codeigniter.com/wiki/Category:Help::Tutorials

Do a search on this forum for tutorials, there are several, some more complex than others, but they offer other ways of using CI.

Ask questions on the forum, please, we don't bite (much <g>).
#4

[eluser]the_unforgiven[/eluser]
Hi thanks for your reply, I will check that out and I've been referring to the user guide too.

I have a welcome controller that sees to control everything I have set up header, content, footer and container views but i need to put some code in like
Code:
if ($_POST['page']=='welcome' {

do this

}

else {

Do nothing

}
But cant seem to get the actuall route as it where right.
#5

[eluser]the_unforgiven[/eluser]
Maybe this will help

Pasted all the container page on pastebin here -> http://pastebin.com/A5pxsSSk to save on space.
#6

[eluser]TWP Marketing[/eluser]
[quote author="the_unforgiven" date="1307664543"]
But cant seem to get the actuall route as it where right.[/quote]

I think I understand that. Follow the data flow; model->controller->view

Set up your data first, in the controller, via your model(s).
Your data (an array) will be passed to the view from the controller.

Controller:
Code:
$view_data = array();
$view_data['header'] = $this->Your_model->load_view_header();
$view_data['footer'] = $this->Your_model->load_view_footer();

//Conditionally set the body content

switch( $_POST('page') ){
case 'welcome':
  $view_data['body'] = $this->Your_model->load_welcome_body(); // probable the welcome page
  break;

case 'page_2':
  $view_data['body'] = $this->Your_model->load_page_2_body(); // data for next page
  break;
...

default:
  $view_data['body'] = $this->Your_model->load_welcome_body(); // default if no page_name is POSTed
  break;
}

$this->load->view('view_name',$view_data); // pass header, footer and body data to browser
...

In the view file, you will be able to echo any element of the three arrays: $header, $footer, $body
View:
Code:
...
&lt;body&gt;
&lt;?php echo $header['name'];?&gt;
...
&lt;?php echo $header['logo');?&gt;
...
&lt;?php echo $body['something'];?&gt;
...
&lt;?php echo $footer['xyz'];?&gt;
&lt;/body&gt;

This is a simplified structure and the view you pastebin'd is much more complex. I see that you are calling the CI loader from within the view file. I have never done that myself and I see potential problems with that approach. I would create any needed data structures (menus, images, text, forms, etc.) in the controller/model and simply pass that data to the view, using the CI loader. Technically, you don't need a model, but it could greatly simplify the controller code.

If this doesn't make enough sense, please feel free to ask.
#7

[eluser]the_unforgiven[/eluser]
Hi thanks for that, I think I understand it, so i don't really need a model then, would the above controller be a new page then same with the view file.

Because the pastebin code was the container.php page which is the index.php page if you like that show everything, so would I just do a new controller page then put all the views stuff on that container.php page then?
#8

[eluser]the_unforgiven[/eluser]
I also have this piece of code in welcome.php which is the main controller for everything
Code:
function customeraccount() {
        // Show Customer Account
        
            
        if ($this->input->get('customer_id')){
                $fdata = $this->input->get('customer_first_name');
                $ldata = $this->input->get('customer_last_name');
                $phonedata = $this->input->get('phone_number');

                if (isset($_SESSION['customer_id'])){
                        flashMsg('success',lang('login_logged_in'));
                        redirect( $this->module.'/customeraccount','refresh');
                }
                flashMsg('info',lang('login_email_pw_incorrect'));
                redirect( $this->module.'/customeraccount','refresh');
        }
                
        $data['title']=$this->preference->item('site_name')." | ".'Edit Your Account';
        $data['page'] = $this->config->item('backendpro_template_shop') . 'customeraccount';
        $data['module'] = $this->module;
        $this->load->view($this->_container,$data);
    
    //print_r($data);

        
    }
    
    function editcustomeraccount() {
    
          
        
        $data['title']=$this->preference->item('site_name')." | ".'Edit account';
        $data['page'] = $this->config->item('backendpro_template_shop') . 'editcustomeraccount';
        $data['module'] = $this->module;
        $this->load->view($this->_container,$data);
    
    }
    function customerOrders() {
    
        //Shows Orders
        echo 'Show Orders code';
    }
#9

[eluser]TWP Marketing[/eluser]
[quote author="the_unforgiven" date="1307710359"]Hi thanks for that, I think I understand it, so i don't really need a model then, would the above controller be a new page then same with the view file.

Because the pastebin code was the container.php page which is the index.php page if you like that show everything, so would I just do a new controller page then put all the views stuff on that container.php page then?[/quote]

Ok, this may get complicated, so bear with me.

Re using models; no you don't need to use them, YES, they make your code easier to understand. I use them, extensively. If you find your controller is getting too large, move data access and manipulation code into models. I come from a procedural coding background (yeah, I'm that old), and huge files were normal, but a nightmare to debug and document. Please DO consider using models per the MCV architecture.

Next, I see that your code uses the GET variables, because your links are not built around the defacto CI segmented uri's. You CAN do this, BUT, you will spend large amounts of time fighting the CI system (opinion). Please read this thread for some background on the argument around CI's segmented uri vs GET: http://ellislab.com/forums/viewthread/56389/

Next, check the User Guide http://ellislab.com/codeigniter/user-guide/ and decide whether you want to design your project using CI's URI Segment approach: /controller/function/var1... or the $_GET array format. The thread above discusses many of the pro's and con's for these approaches. To be honest, when I start a new project (as you are here?) I really prefer the segmented uri's. They make sense in the [edit] MCV design model (personal opinion, your mileage may vary and other opinions are valid. So please, no flames from the rest of the community).

Looking at your Pastbin'd code, I see that you have some experience in PHP. That code is built using the GET array to pass variables. Yes it can be made to work, but you'll miss a lot of CI's ease-of-use and spend more time doing work-arounds. (Again, personal opinion...).

And yes this is verbose and I apologise but I hope it helps.
#10

[eluser]the_unforgiven[/eluser]
Thanks mate

Thats makes a lot more sens so I would be better off doing the following:

Write my own, Controller, Model, View

Write new views files to include header, content and footer etc

If i understand what you have said in both posts you made that is.... Smile
I will have a go and see what happens and let you know, much appreciate the help you given and I hope to get this working.

Thanks again




Theme © iAndrew 2016 - Forum software by © MyBB