[eluser]featureBlend[/eluser]
Im on a local Apache 2.06 / PHP 5.2.6 / MY SQL 5+ Environment
A simple logical observation and explanation ---> I am not using short tags and the tutes that Derek posted do, so if you are in the same position as me then read on..
I had done everything according to the tute, but when i pressed the submit button in the comments_view there was no response..Heres the files
BEFORE i figured it out:
1. blog.php (Front Controller)
Code:
<?php
class Blog extends Controller {
function Blog()
{
parent::Controller();
$this->load->scaffolding('entries');
$this->load->database();
$this->load->helper('url');
$this->load->helper('form'); //loaded the helpers
}
function index()
{
$data['title']="Ahads Page with CI";
$data['heading']="My Blog Heading";
$data['query']= $this->db->get('entries');
$this->load->view('blog_view', $data);
}
function comments()
{
$data['title']="My Comment Title";
$data['heading']="My Comment Heading";
$this->load->view('comment_view', $data);
}
function comment_insert()
{
echo 'testing 1,2,3'; //lets test that function in the comment_view
}
}
?>
2. comment_view.php (View file for comment page)
Code:
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $heading; ?></h1>
///hmmm what could be wrong with the syntax here?
//should i open the form tag with the html syntax <form>?
//i tried to use the form syntax, the button started working but not quite the way i wanted it
<?php form_open('blog/comment_insert'); ?>
<?php form_hidden('entry_id',$this->uri->segment(3));?>
<p><textarea name="body" rows="10"></textarea></p>
<p><input type="text" name = "author" /></p>
<p><input type="submit" value="Submit Comment" /></p>
</form>
</body>
</html>
No response from the Submit button from the above code..Why? I knew it was something with my syntax in one of the files.
Was it the <form> tag in the comments_view (but i called the form helper class from the controller so it should handle the request right?, RIGHT), or some other syntax error.
See below:
Code:
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $heading; ?></h1>
<?php echo form_open('blog/comment_insert'); ?>
<?php echo form_hidden('entry_id',$this->uri->segment(3));?>
<p><textarea name="body" rows="10"></textarea></p>
<p><input type="text" name = "author" /></p>
<p><input type="submit" value="Submit Comment" /></p>
</form>
</body>
</html>
I failed to add the "echo" STATEMENT before (1) form_open and (2) form_hidden in my comments_view file.
What is the echo statement?
In flat files the syntax would be:
Code:
void echo (string argument [,...string argumentN])
The echo() statement operates similarily to print(), except for two differences.
1 - It cannot be used as a part of a complex expression because it returns void()
2 - echo() is capable of outputting multiple strings (see below)
For example:
Code:
<?php
$easier = "Code Igniter";
$harder = "Symfony";
echo $easier, " and " , $harder, " are great frameworks. ", " Learn CI first though.....If the dudes who created CI follow the KISS approach, then so shall we. ";
?>
Try to develop good habits and "familiarize" yourself with flat php syntax as well....