Welcome Guest, Not a member yet? Register   Sign In
Hello world tutorial
#1

[eluser]downah[/eluser]
Hi guys,

I am trying out the hello world tutorial

this is what I have in blog.php

Code:
<?php

class Blog extends Controller {

function index()
{
  echo "Hello World!";
}

}

?>

I try going to website.com/codeigniter/index.php/blog/ and it loads a blank page.. I even try to specify by going to website.com/codeigniter/index.php/blog/index/ but it doesnt work either no errors are showing or anything, what am I doing wrong?

Much appreciated
#2

[eluser]downah[/eluser]
hmm I just read in the documentation

Code:
<?php
class Blog extends CI_Controller {

public function index()
{
  echo 'Hello World!';
}
}
?>

and that works, is the tutorial on the main website outdated? can anyone explain it to me ? Smile
#3

[eluser]skunkbad[/eluser]
Yes, it is outdated.
#4

[eluser]downah[/eluser]
Thanks for the quick reply, is the blog tutorial also outdated?
#5

[eluser]skunkbad[/eluser]
[quote author="downah" date="1343498075"]Thanks for the quick reply, is the blog tutorial also outdated? [/quote]

Yes, I believe it is also outdated. If you'd like to see how you can handle many common website solutions, and how CI works, you might consider downloading my Community Auth application. It is already installed in CI 2.1.2:

https://bitbucket.org/skunkbad/community...et/tip.zip
#6

[eluser]downah[/eluser]
Well no not really but thanks, one of the main reasons I started playing around with CI is because of the video tutorials.. but knowing they would have outdated code right there playing on their main website for new users to see... maybe cakePHP is more what I am looking for Smile
#7

[eluser]skunkbad[/eluser]
[quote author="downah" date="1343500820"]Well no not really but thanks, one of the main reasons I started playing around with CI is because of the video tutorials.. but knowing they would have outdated code right there playing on their main website for new users to see... maybe cakePHP is more what I am looking for Smile[/quote]

There are a lot of video tutorials at Nettuts+. They have a "CodeIgniter From Scratch" series. The first one is here:

http://net.tutsplus.com/articles/news/co...tch-day-1/

These tutorials are more or less relevant to the current version of CI.

If you've never used a PHP framework, then you'll find that CI is the easiest to learn. All the CI forum members that don't know a dang thing about PHP is probably a testimony to that.
#8

[eluser]downah[/eluser]
Thanks for those tutorials, will have a look at them and see where that leads me with CI, I have done some small things with ZF and like it but it is huge, and a fair share of PHP programming.

I just hate things like outdated tutorials on the main page!! Wink
#9

[eluser]downah[/eluser]
So far enjoying the tutorials, thanks again for letting me know about them.

I have got a small error though for hope someone here could help and don't feel the need to create a new thread.

I am getting this error:


A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$title

Filename: views/home.php

Line Number: 19


home:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

&lt;html xml:lang="en" lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;

&lt;title&gt;home&lt;/title&gt;

&lt;/head&gt;

&lt;body&gt;
<div id="container">
<p>View has been loaded.</p>


&lt;?php foreach($records as $row) : ?&gt;
  
  <h1>&lt;?php echo $row->title; ?&gt;</h1>
  
  &lt;?php endforeach; ?&gt;
</div>
&lt;/body&gt;
&lt;/html&gt;

Active records are set to true

this is the model:
Code:
&lt;?php
class Site_model extends CI_Model {

function getAll(){
  $q = $this->db->get('items');
  
  if($q->num_rows() > 0){
   foreach ($q->result() as $row)
   {
    $data[] = $row;
   }
  return $data;
  }

}


}



?&gt;

and this is the controller:

Code:
&lt;?php
class Site extends CI_Controller {

function index(){
  $this->load->model('site_model');
  $data['records'] = $this->site_model->getAll();
  $this->load->view('home', $data);
  
}

}


?&gt;

Any help greatly appreciated!
#10

[eluser]skunkbad[/eluser]
Are there actual records being returned?

In your model, there's no reason to foreach over the result set. Just simply return q->result().

Code:
if( $q->num_rows() > 0 )
{
     return $q->result();
}

// You will always want to return something if there was no result set
else
{
     return FALSE;
}

Then, in your view:
Code:
// Make sure records is not FALSE
if( $records )
{
     foreach( $records as $row )
     {
          echo '<h1>' . $row->title . '</h1>';
     }
}
else
{
     echo '<p>No Results To Show</p>';
}




Theme © iAndrew 2016 - Forum software by © MyBB