Welcome Guest, Not a member yet? Register   Sign In
Can someone help a newbie out?
#1

[eluser]BenBrah[/eluser]
I followed this http://www.youtube.com/watch?v=gvGymDhY49E
Creating Your First Template With CodeIgniter

Updated the controller to CI_controller

Basically when i go to
http://influencearticles.com/index.php/site/about_us

It should be calling the about_us.php information and adding it to the middle

and again with

http://influencearticles.com/index.php/site/contact_us

But I'm getting errors on all 3 including just /site

Can anyone tell me where i've gone wrong please?


Site / Controller
Code:
<php

class SITE extends CI_controller {

  function contact_us()
  {
        &data;['main_content'] = 'contact_us';
  $this->load->view('template', &data;);
  }
  
    function about_us()
  {
        &data;['main_content'] = 'about_us';
  $this->load->view('template', &data;);
  }
  
}

header
Code:
<!DOCTYPE html>

&lt;html lang="en"&gt;
&lt;head&gt;
  &lt;meta http-equiv="Content_Type" content="text/html; charset=utf-8"&gt;
  &lt;title&gt;untitled&lt;title&gt;
&lt;/head&gt;
&lt;body&gt;
<p>this comes from the header view</p>

footer
Code:
<p>This is the footer</p>
&lt;body&gt;
&lt;/html&gt;

about us
Code:
<p>This is the about us page.</p>

and finally contact us page
Code:
<p>This is the contact us page.</p>
#2

[eluser]CroNiX[/eluser]
You are getting an error when you just go to "site" because you don't have an index method in your Site class, which is what gets loaded if no method is used in the url.

Site should be "Site", not "SITE" in your class declaration. CI_Controller, not CI_controller.

Your other errors are because you have a semicolon after "data" and are using & where you should be using $ in your variables. You left the $ off of data. Those are very basic php things. Are you sure you are ready for CI?

Code:
class Site extends CI_Controller {

  function index()
  {
    //load some default view?
  }

  function contact_us()
  {
    // Wrong: &data;['main_content'] = 'contact_us';
    $data['main_content'] = 'contact_us';
    //Wrong: $this->load->view('template', &data;);
    $this->load->view('template', $data);
  }

  //make the same changes to about_us() as I did to contact_us()
}
#3

[eluser]pbflash[/eluser]
What errors are you receiving? I'm guessing it's because of the &data; which should be $data. Try the below code:
Code:
<php

class SITE extends CI_controller {

  function contact_us()
  {
     $data['main_content'] = 'contact_us';
     $this->load->view('template', $data);
  }
  
    function about_us()
  {
      $data['main_content'] = 'about_us';
      $this->load->view('template', $data);
  }
  
}
#4

[eluser]BenBrah[/eluser]
Thanks guys. I've edited the code and its still not doing what it shows in the video and i can't see any errors or mistakes what are causing this.

I'll try another tutorial and CroNiX i thought ci would be a good place to start learning? :p
#5

[eluser]CroNiX[/eluser]
If you don't understand the underlying language that CI is written on top of, you will not have a very easy time. It'd be like taking Algebra without knowing basic math. You will have one big learning curve. Can it be done? Sure, but it will be a lot harder than taking things in order.

I'm guessing your remaining errors are in your template.php file. What are the actual errors? Also, your opening php tag should be &lt;?php
#6

[eluser]BenBrah[/eluser]
Thanks updated Smile

template_php
Code:
&lt;?php

$this->load->view('includes/header');

$this->load->view($main_content);

$this->load->view('includes/footer');

?&gt;

Actual errors... It's failing to bring the pages up at all. When there clearly there

load->view('template', $data); } function about_us() { $data['main_content'] = 'about_us'; $this->load->view('template', $data); } }

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/inflscom/public_html/application/controllers/site.php:17)

Filename: core/Common.php

Line Number: 438

404 Page Not Found

The page you requested was not found. <-- how can the page not be found when its blatantly there and i presume being summoned correctly?
#7

[eluser]pbflash[/eluser]
What are the files names of the template, about_us, and contact_us pages?
#8

[eluser]BenBrah[/eluser]
[quote author="pbflash" date="1329875393"]What are the files names of the template, about_us, and contact_us pages?[/quote]

about_us.php and contact_us.php?
#9

[eluser]pbflash[/eluser]
What about the template, header, and footer files and where are they saved on the server?
#10

[eluser]CroNiX[/eluser]
Remove all php ending tags from all files.




Theme © iAndrew 2016 - Forum software by © MyBB