• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie "Logical" Observation: Get your sytax Correct!!!!!!!

#1
[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>&lt;?php echo $heading; ?&gt;</h1>

///hmmm what could be wrong with the syntax here?
//should i open the form tag with the html syntax &lt;form&gt;?
//i tried to use the form syntax, the button started working but not quite the way i wanted it
&lt;?php form_open('blog/comment_insert'); ?&gt;

&lt;?php form_hidden('entry_id',$this->uri->segment(3));?&gt;

<p>&lt;textarea name="body" rows="10"&gt;&lt;/textarea></p>
<p>&lt;input type="text" name = "author" /&gt;&lt;/p>
<p>&lt;input type="submit" value="Submit Comment" /&gt;&lt;/p>

&lt;/form&gt;
    

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

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 &lt;form&gt; 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:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<h1>&lt;?php echo $heading; ?&gt;</h1>


&lt;?php echo form_open('blog/comment_insert'); ?&gt;

&lt;?php echo form_hidden('entry_id',$this->uri->segment(3));?&gt;

<p>&lt;textarea name="body" rows="10"&gt;&lt;/textarea></p>
<p>&lt;input type="text" name = "author" /&gt;&lt;/p>
<p>&lt;input type="submit" value="Submit Comment" /&gt;&lt;/p>

&lt;/form&gt;
    

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

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:
&lt;?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. ";
?&gt;

Try to develop good habits and "familiarize" yourself with flat php syntax as well....

#2
[eluser]GSV Sleeper Service[/eluser]
Not sure what point you're trying to make here.. a quick glimpse at the documentation would have told you that you need to echo the response from the form helpers.

#3
[eluser]Nick Husher[/eluser]
Long syntax is to short syntax as "&lt;?php echo ${YOUR_EXPRESSION} ?&gt;" is to "&lt;?=${YOUR_EXPRESSION} ?&gt;".

I'm not sure I see the issue. The syntax error was yours.

#4
[eluser]featureBlend[/eluser]
@Nick, GSV - point noted, yes I agree, the syntax error was mine. The title to this post should have read "Newbie Syntax Mistake: Yadda yadda yadda" - or something to that effect.

The only reason for the post was to contribute to newbies who might learn from my "foolish" mistakes.. I did read a post earlier about a CI user who took 2 weeks to see that little "Table of Contents" tab on the user guide.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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