Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Does not run Hello world
#1

[eluser]codeman[/eluser]
hi Guys,

I started learning Code Igniter Today and i am not able to run hello world program,

SO i have Localhost, i installed apache and Mysql and everything, I tried running PHP code as well works fine,

So i did download codeigniter and put it in the localhost and try to create first controller like this....
<?php
class Blog extends Controller {

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

Now i go to the path http://IP/CodeIgniter/index.php/blog

and it does not print Hello world, What should i do?

What am i doing wrong?

Please help me
#2

[eluser]Jagar[/eluser]
Does PHP works?

What does it display on screen?

Change your code to this with constructor

Code:
class Blog extends controller{
   function Blog(){
      parent::Controller;
   }
  
   function index(){
          echo "hello world";
}

}

How that helps
#3

[eluser]Jagar[/eluser]
Each time you extend the controller you have to call the Controller constructor otherwise you wouldn't be able to use the stuff.

if you have php 5 you can do the following for constructor

Code:
function __construct(){
        parent::Controller();
    }

Good luck!
#4

[eluser]Dam1an[/eluser]
[quote author="Jagar" date="1240871612"]Each time you extend the controller you have to call the Controller constructor otherwise you wouldn't be able to use the stuff.
[/quote]

You don't have to, you only need to call the parent constructor if you have your own constructor
#5

[eluser]jdfwarrior[/eluser]
[quote author="Dam1an" date="1240873775"][quote author="Jagar" date="1240871612"]Each time you extend the controller you have to call the Controller constructor otherwise you wouldn't be able to use the stuff.
[/quote]

You don't have to, you only need to call the parent constructor if you have your own constructor[/quote]

Agreed. I never use a constructor.
#6

[eluser]Jagar[/eluser]
Thanks for correcting me. Learning something new everyday Smile
#7

[eluser]Dam1an[/eluser]
I'm not sure if the forum converted your quotes, but if I copy and paste your code, its not standard single quotes :S
#8

[eluser]jdfwarrior[/eluser]
[quote author="Dam1an" date="1240874201"]I'm not sure if the forum converted your quotes, but if I copy and paste your code, its not standard single quotes :S[/quote]

They may be using the auto typography function for the posts.
#9

[eluser]Dam1an[/eluser]
[quote author="jdfwarrior" date="1240874441"][quote author="Dam1an" date="1240874201"]I'm not sure if the forum converted your quotes, but if I copy and paste your code, its not standard single quotes :S[/quote]

They may be using the auto typography function for the posts.[/quote]

I know they might be, but I was just checking he wasn't using the wrong sort of quotes for an echo, although if he was, I'd expect an error
#10

[eluser]jdfwarrior[/eluser]
@Codeman It's hard to say what it could be. If PHP was working and you simply dropped in CodeIgniter, things should work unless the path's are incorrect or something. I just used this code and it worked.

Code:
<?php

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

class Blog extends Controller
{
    function index()
    {
        echo 'hello world';
    }

}

Edit: Which, now I just noticed. The single quotes I put in this post, aren't converted to anything else due to auto typography. So, you obviously have some funny symbols being used. Replace your quotes with actual single (or double) quotes. Do you get any kind of error message?




Theme © iAndrew 2016 - Forum software by © MyBB