• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI tutorials failed and code did not work - bad code or my setup?

#1
[eluser]ICEcoffee[/eluser]
Hi all, I'm pulling my hair out here. I am trying to learn oop and MVC, and after much investigation, I believe CI is the right choice, but after following the tutorials/code examples, on the CI site (it's irrelevant at the moment which ones), I almost always have the code breaking. I obviously check to make sure there are no typos etc.

I want to ask (and I have search the forums on this), just to be absolutely clear, can I use CI on my XAMPP system that is configured with php5, as long as I code in php4 and not php5? will a php5 server render all php4 correctly?

It didn't cross my mind that Derek Jones' code was incorrect, and thought it was my testing environment. So I started to play around with the latest Zend Framework, but it's causing my brain to cramp. I can cope with PHP procedural, but I think I need an easy a path as possible to get up to speed with OOP and MVC frameworks.

If I can have a definitive answer like: "yes, you can use CI on a php5 server, as long as you code in PHP4 only, it will not be your environment to blame for a broken app", I'll continue to throw myself into CI.

#2
[eluser]richthegeek[/eluser]
there is little difference between php4 and php5 - the only difference that affects CI directly is method chaining. If your server is PHP5 don't worry about it.

The tutorials I tried to get started all worked fine for me in CI on a LAMP install (PHP5, Apache 2.2).

It is likely that there are typo's in your code - if you aren't used to standard PHP OOP it might be hard for you to jump straight in with CI.

#3
[eluser]ICEcoffee[/eluser]
If it's not my PHP5 environment, then should I be writing PHP4 or PHP5 compatible code?

#4
[eluser]Pascal Kriete[/eluser]
If you use PHP 5 it will only run on hosts that have PHP 5 installed. PHP 4 will run on hosts using 4 or 5. So 4 is the more compatible, it's also a huge pain in the rear to support. Not to mention that it's a deprecated language.

The reason why CI still supports PHP 4 is because it is still used by a lot of hosts.

So to answer your question: It depends on the server. If this will be on your server only, I highly suggest php 5. In fact, I highly suggest it either way.

#5
[eluser]ICEcoffee[/eluser]
@inparo: thanks for your helpful reply.

an example of the problem I'm having:
I pretty much copied and pasted the code below from the CI user manual, models page, but when I point browser to class, I get the '404 error' message.

Model: filename = blog_model.php (all lower case)
Code:
<?php
class Blog_model extends Model
{
    var $title   = '';
    var $content = '';
    var $date    = '';
    
    function Blog_model()
    {
        parent::Model();

    }
    
    function get_last_ten_entries()
    {
        $query = $this->db->get('blog', 2);
        return $query->result();
    }
    
}
?>



Controller: filename = blog_controller.php
Quote:<?php
class Blog_controller extends Controller {

function blog()
{
$this->load->model('Blog');

$data['query'] = $this->Blog->get_last_ten_entries();

//dont want to go to view yet - $this->load->view('blog', $data);
}
}
?>

database table name is 'blog', with 2 entries.

I have edited the database.php file, and re-checked details.
my browser is pointing to: http://localhost/ci/index.php/blog

is it something I've done wrong?

#6
[eluser]richthegeek[/eluser]
why are you appending _model and _controller? There is no need.

http://www.example.com/index.php/blog/view/10

will go to

/system/application/controllers/blog.php

and look for the class::method of

Blog::view()

#7
[eluser]Pascal Kriete[/eluser]
You forgot a constructor in your controller.
Code:
function Blog_Controller()
{
    parent::Controller();
}

#8
[eluser]ICEcoffee[/eluser]
Quote:You forgot a constructor in your controller.

you're right there was no constructor for the controller, I did add it, but I still get the 404 not found error.

2 points however:
1. I copied and pasted the controller code straight from the CI user manual, so shouldn't this include a constructor too, if required?

2. I thought a constructor was not mandatory, only if you wanted to run code when the controller is loaded.

any thoughts, why I might still be getting a 404?

#9
[eluser]Pascal Kriete[/eluser]
You're right, it isn't mandatory. But if you want access to the CI super object you will need the constructor.

Quote:my browser is pointing to: http://localhost/ci/index.php/blog

It's www.example.com/controller/function, so do:
Quote:http://localhost/ci/index.php/blog_controller/blog


If that doesn't work try reducing the code even further. Does something like this work:
Code:
<?php
class Blog_controller extends Controller {

    function blog()
    {
        echo 'test';
    }
}
?>

#10
[eluser]ICEcoffee[/eluser]
your right about the url being incorrect, I spotted this and made the change, and no longer get a 404, but am getting other errors.

so I think I will do as you suggested and reduce code, and build (and learn) from there. Thanks.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.