Welcome Guest, Not a member yet? Register   Sign In
Blog video tutorial problem
#1

[eluser]ApranaxFort2[/eluser]
Hi, i have trouble with CI. I am newbie and i am working to understand CI. I coulnt pass the tutorial.


I wrote this code (controllers/blog.php) but i cant see anything in browser. There is no Error or else.
Code:
<?php

class Blog extends Controller {

    function Blog()
    {
        parent::Controller();
        
        //$this->load->scaffolding('entries');
    }
    
    function index()
    {
        $data['title'] = "My Blog Title";
        $data['heading'] = "My Blog Heading";
        $data['todo'] = array('deneme bir', 'ikinci deneme', 'bu ucuncu deneme', 'dorduncu deneme de bu')//$this->db->get('entries');
        
        $this->load->view('blog_view', $data);
    }
}
?>

my php version is 5 and CI version is 1.6.3
#2

[eluser]Pascal Kriete[/eluser]
You're missing a ; after your array Smile .
Code:
$data['todo'] = array('deneme bir', 'ikinci deneme', 'bu ucuncu deneme', 'dorduncu deneme de bu');  //$this->db->get('entries');

Welcome to CodeIgniter.
#3

[eluser]ApranaxFort2[/eluser]
:red: Oh i am sorry. Thank you for your help. I fixed it but i get same problem.

This is my blog_view.php
Code:
<html>
<head>
<title> <?php echo $title;?> </title>
</head>
<body>
<h1>&lt;?php echo $heading;?&gt;</h1>
&lt;?php foreach($todo as $row); ?&gt;
<h3>&lt;?php echo $row;?&gt;</h3>
<hr />
&lt;?php endforeach; ?&gt;
&lt;/body&gt;
&lt;/html&gt;

I am new in PHP too. I was a ASP developer. Maybe there is a syntax problem in this page but i couldn't see.

Is there a way to get errors detailed. I cant understand anything when i get blank page.
#4

[eluser]Pascal Kriete[/eluser]
You can turn on display errors, either in your php.ini file or by putting this in your index.php:
Code:
ini_set('display_errors', '1');

There is one more syntax error that I can see. When you're using the php alternative syntax, you need a colon, not a semicolon.
Code:
&lt;?php foreach($todo as $row): ?&gt;
#5

[eluser]ApranaxFort2[/eluser]
Thank you so much. I fixed my all problems. Smile
I must improve my php syntax knowledge Smile
#6

[eluser]ApranaxFort2[/eluser]
Now when i using database class i get error.


"Fatal error: Call to a member function get() on a non-object in /var/www/html/citry/system/application/controllers/blog.php on line 15"

This is my blog.php
Code:
&lt;?php

class Blog extends Controller {

    function Blog()
    {
        parent::Controller();
        
    }
    
    function index()
    {
        $data['title'] = "My Blog Title";
        $data['heading'] = "My Blog Heading";
        $data['query'] = $this->db->get('entries'); //THIS IS LINE #15
        
        $this->load->view('blog_view', $data);

    }
}
?&gt;

And i was change config/autoload.php in this line

Code:
$autoload['core'] = array('database');
#7

[eluser]Pascal Kriete[/eluser]
There have been a few changes since the video tutorials were made, and one of them is libraries.

The core autoload array has been deprecated in favor of the libraries array (I believe it's documented in the code as well), so try this:
Code:
$autoload['libraries'] = array('database');

And if that fails to work, you can always load a library on-demand to save memory for functions that don't use it (session and database are two I tend to autoload):
Code:
$this->load->library('database');

$data['title'] = "My Blog Title";
$data['heading'] = "My Blog Heading";
$data['query'] = $this->db->get('entries'); //THIS IS LINE #15

If both of those fail, there is an issue elsewhere.
#8

[eluser]igniter23[/eluser]
I'm following the blog video tutorial where the comments are being created but I'm getting an 404 page not found error when I click the 'comment' link and the browser points to the link below; instead of the '...blog/comments/1' of the tutorial.

http://127.0.0.1/CodeIgniter/index.php/blog/comments1

Is there something missing that I might over looked? Please help. Thanks in advance.
#9

[eluser]Pascal Kriete[/eluser]
Looks like you're just missing a slash. Could you show us the code used to generate that link?
#10

[eluser]igniter23[/eluser]
Here's the code that I'm following from the video tutorial.

Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;?=$title?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<h1>&lt;?=$heading?&gt;</h1>

&lt;?php foreach($query->result() as $row): ?&gt;

<h3>&lt;?=$row->title?&gt;</h3>
<p>&lt;?=$row->body?&gt;</p>

<p>&lt;?=anchor('blog/comments'.$row->id, 'Comments');?&gt;</p>

<hr>

&lt;?php endforeach; ?&gt;


&lt;/body&gt;
&lt;/html&gt;




Theme © iAndrew 2016 - Forum software by © MyBB