Welcome Guest, Not a member yet? Register   Sign In
n00bz question
#1

[eluser]solidhex[/eluser]
Hey all

New to CodeIgniter. I have what I think is a pretty simple question (and presumably has a pretty simple answer).

Let's say I have a page that displays comments. Underneath the comments I have a link that says, 'Add a comment.' When that link is clicked, I want to show the comment form (duh!).

If I were writing PHP from scratch, I could add a query string to the link like so:

Code:
<a href="foo.php?add_comment=yes">add a comment!</a>

I could then read that value using $_GET or $_REQUEST. How can I set that link to be CI friendly so I can use the uri class?
#2

[eluser]nmormino[/eluser]
CodeIgniter doesn't use $_GET what you have instead is a controller that handles a certain type of page. for example :

http://yourdomain.com/controller/method/variable

in your controller you will have a method

function method(variable) {
}

hope this helps, if not, then I would recommend doing the build a blog in 15 minutes tutorial

http://codeigniter.com/tutorials/watch/blog/
#3

[eluser]NateL[/eluser]
Yep, that video tutorial is great for getting your head around the idea of how the URI's work. You don't really have to deal with ?function=dothis
#4

[eluser]solidhex[/eluser]
Yep I watched over the tutorial. I think my question is more about the view file. My view file contains both the form and the comments, but I only want to display the comment form when the user clicks the 'Add a comment' link. I realize this could easily be done with JavaScript, but I am simply experimenting with CI to get my head around how it works.
#5

[eluser]indocoder[/eluser]
if you using the global "view" file , use the IF ELSE statement inside the view for each method but I really not recommend this as a good solution for a beginner.
#6

[eluser]NateL[/eluser]
OH! Sorry..

For that, I don't think you would need PHP at all. just jQuery.

Perfect tutorial for you:

http://blog.themeforest.net/screencasts/...ers-day-6/
#7

[eluser]solidhex[/eluser]
Ah yes, but as I mentioned I was trying to set it up without javascript - that I know I could do easily Smile I just wanted to test out how to do stuff with CI.
#8

[eluser]solidhex[/eluser]
Here is what the full page would look like, we'll call it index.php:

Code:
<ol>
    <li>
        First Comment
    </li>
    <li>
        Second Comment
    </li>
</ol>

<p><a href="index.php?add_comment=yes">Add a comment</a></p>

&lt;?php if (isset($_REQUEST['add_comment']) && $_REQUEST['add_comment'] == 'yes') : ?&gt;
    
    &lt;form action="#" method="post" accept-charset="utf-8"&gt;
        &lt;input type="text" name="email" value="" id="email" /&gt;
        &lt;textarea name="comment" rows="8" cols="40"&gt;&lt;/textarea>
        <p>&lt;input type="submit" value="Continue &rarr;" /&gt;&lt;/p>
    &lt;/form&gt;

&lt;?php endif; ?&gt;

I suppose I could create two separate views, but that seems wasteful. I think I need to pass in variable via the controller, yes?




Theme © iAndrew 2016 - Forum software by © MyBB