We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

send velue with http GET request

Hello. I do not know how send velue with GET REQUEST, i Have database with table videos

it is my VideoController


      public function indexAction()
    {

        if ($this->request->isGet()) {

         $id = $this->request->getQuery("id");
         $name = $this->request->getQuery("name");
         $poster_url = $this->request->getQuery("poster_url");
         $source_url = $this->request->getQuery("poster_url");
         $this->view->video = Videos::find();

        }

whan i start to play video i get https://localhost/project/videos/ this url , i want to get videos with id and get videos/1 videos/2 etc...



43.9k

Hi,

in your function indexAction(), do a

var_dump(array($id, $name, $poster_url, $source_url));

to see if you catch the request parameters with : $this->request->getQuery(PARAM);

edited May '15

hi le51, i get this

array(4) { [0]=> NULL [1]=> NULL [2]=> NULL [3]=> NULL }

okey i solved this problem

$this->view->video = Videos::find($id);

i get id=1, id=2 .. etc



92

You can simplify your code - you don't need the name or urls. This will also allow you to use videos/index/1, videos/index/2 etc

public function indexAction($id = 0)
    {
        if ($id) {
            $this->view->video = Videos::find($id);
        }
    }
        if ($this->request->isGet()) {

         $id = $this->request->getQuery("id", 'int');

         $this->view->videos = Videos::find($id);

         if ($id == null) {

         $this->response->redirect(''); 

         }

      }

thank u Aimee , but my code work well



92
    if ($id == null) {
        $this->response->redirect(''); 
    }

This statement is a little benign - if id == null the statement before will produce an error. By moving this statement and including an if/else statement up you can prevent an unnessecary database query and error:

    if ($this->request->isGet()) {
        $id = $this->request->getQuery("id", 'int');

        if ($id == null) {
            $this->response->redirect(''); 
        } else {
            $this->view->videos = Videos::find($id);
        }
    }


92

Just something else to help: Given that you are querying by id, this is implying you will only ever return one result. It is not clear from your original post, but if this is the case, you should use Videos::findFirst($id). This will return a single Video object with no loop needed in your view.

Just something else to help: Given that you are querying by id, this is implying you will only ever return one result. It is not clear from your original post, but if this is the case, you should use Videos::findFirst($id). This will return a single Video object with no loop needed in your view.

i can not get only one result, i get other result with id (id=1)(id=2)

it is my view code

<?php foreach ($videos as $video) {} ?>

<?php echo "$video->source_url"; ?>

<?php echo "$video->poster_url"; ?>