0

Im trying to send 2 arguments to my controller method from my view using GET.
I don't know exactly how to add my 2nd argument to the action URL.

Here I am sending only 1 argument.

 action="/MVC/teacher/lookspecificMessage/<?= $details['person_receive_id']; ?>" method="GET">

However, I want to add this <?= $details['related_message']; ?>

I've tried using lookspecificMessage/<?= $details['person_receive_id']; ?>&<?= $details['related_message']; ?> but it dosen't work.

2
  • Take a look at this question. stackoverflow.com/questions/13102489/… Commented May 14, 2017 at 17:55
  • try using action ="<?php echo "/MVC/teacher/lookspecificMessage/" . $details['person_receive_id'] . "&" . $details['related_message']; ?>" Commented May 14, 2017 at 18:00

2 Answers 2

1

If URL rewriting is used, url should follow declared template.

In your case it can be

action="/MVC/teacher/lookspecificMessage/$person_receive_id/$related_message"

or

action="/MVC/teacher/lookspecificMessage/$person_receive_id/lookrelaredMessage/$related_message"

or any other form.
You should check rewriting rules to find correct template for url.

Sign up to request clarification or add additional context in comments.

Comments

0

Using URL rewriting, you can have parameters in the main URL structure like that. Although, typically, GET parameters are passed at the end after a question mark like so:

example.com/path/to/page?param=1

If you want more than one parameter, you use the ampersand to separate them:

example.com/path/to/page?param=1&foo=bar

In your case, it looks like your .htaccess file is doing some URL rewriting or your framework is doing some magic, which is automatically extracting the parameter and setting it in the $_GET array.

And to be clear, here is how you could do yours:

<?php

    // Get params
    $receiveId = (int) $details['person_receive_id'];
    $message = (string) $details['related_message'];

    // Build URL
    $url = "/MVC/teacher/lookspecificMessage/$receiveId?related_message=$message";

    // Encode URL (in case message has weird values)
    $url = urlencode($url);
?>

<form method="GET" action="<?php echo($url); ?>">
     <!-- REST OF FORM HERE -->
</form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.