ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

CodeIgniter Does not run Hello world

April 27, 2009 2:21pm

Subscribe [2]
  • #1 / Apr 27, 2009 2:21pm

    codeman

    15 posts

    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 / Apr 27, 2009 2:32pm

    Jagar

    135 posts

    Does PHP works?

    What does it display on screen?

    Change your code to this with constructor

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

    How that helps

  • #3 / Apr 27, 2009 2:33pm

    Jagar

    135 posts

    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

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

    Good luck!

  • #4 / Apr 27, 2009 3:09pm

    Dam1an

    2385 posts

    Each time you extend the controller you have to call the Controller constructor otherwise you wouldn’t be able to use the stuff.

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

  • #5 / Apr 27, 2009 3:13pm

    jdfwarrior

    444 posts

    Each time you extend the controller you have to call the Controller constructor otherwise you wouldn’t be able to use the stuff.

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

    Agreed. I never use a constructor.

  • #6 / Apr 27, 2009 3:15pm

    Jagar

    135 posts

    Thanks for correcting me. Learning something new everyday 😊

  • #7 / Apr 27, 2009 3:16pm

    Dam1an

    2385 posts

    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 / Apr 27, 2009 3:20pm

    jdfwarrior

    444 posts

    I’m not sure if the forum converted your quotes, but if I copy and paste your code, its not standard single quotes :S

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

  • #9 / Apr 27, 2009 3:25pm

    Dam1an

    2385 posts

    I’m not sure if the forum converted your quotes, but if I copy and paste your code, its not standard single quotes :S

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

    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 / Apr 27, 2009 3:39pm

    jdfwarrior

    444 posts

    @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.

    <?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?

  • #11 / Apr 27, 2009 4:20pm

    Dam1an

    2385 posts

    I just tried his original, with the funny quotes, and it gives a parse error

    Parse error: parse error, expecting `','' or `';'' in C:\xampp\htdocs\project_trackr\controllers\blog.php on line 6

    so thats either not the problem or he neglected to mention the error

  • #12 / Apr 27, 2009 5:38pm

    codeman

    15 posts

    Still Nothing Guys,

    Here is my code and URL I am using

    <?php
    class Blog extends controller{
    
       function __construct(){
            parent::Controller();
        } 
       
       function index(){
              echo "hello world";
        }
    
    } 
    ?>

    and I am using http://my IP/CodeIgniter/index.php/blog/

    I have PHP 5 running on my local Host and PHP 5 is working fine

    Please help me,
    Thanks,

  • #13 / Apr 27, 2009 5:45pm

    Dam1an

    2385 posts

    Put an echo in your constructor, see if it even gets that far

  • #14 / Apr 27, 2009 5:47pm

    jdfwarrior

    444 posts

    Did you move the app or system folders around?  If you just take the system folder and drop it in the root with the index.php it should just work. Are you getting an error? What is it doing? “its not working” doesnt exactly tell us much about whats going on.

  • #15 / Apr 27, 2009 5:56pm

    codeman

    15 posts

    NO echo is not working either and here is my path

    /root/Codeigniter/System/Controllers/Blog.php

    I am not getting any error - it shows blank page with nothing - just white page, sometimes i feel errors are better than no error problems

    I am not sure what ami doing wrong - i am following simple instruction form the code igniter website

    why is it this complicated, By the way great help - you guys are fast in replyinh - unsually great

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases