slim routing and controller (how this __call function is calling from route and why $this->request is...












-2















guys please help me to understand these code



in picture 1 router is calling with info method



as you can see in AccountController there is already info() is present then why __call() this magic function is calling



and what are these parameters is $this->request ,$this->response



we can save all data like



$request = $args[0]; $response = $args[1]; $attributes = $args[2];



why $this-> syntex is use
what is the meaning of this line $this->$name();



Router.php



<?php

$app->get('/account', 'AppControllerAccountController:info');

?>


AccountController.php



<?php
/**
* AccountController
* @package Controllers
*/
namespace AppController;


final class AccountController extends AppCoreController
{

protected function info()
{

echo $this->client_id;

}
}


Controller.php



 <?php

namespace AppCore;


class Controller
{


public function __call($name,$args) { //line 25
//echo "Call method : ".$name;
$this->request = $args[0];
$this->response = $args[1];
$this->attributes = $args[2];

//print_r($this->attributes);
$this->client_id = $this->request->getAttribute("client_id");



$this->$name();

}

}


?>









share|improve this question




















  • 2





    Hi Kershav - can you edit your question to include code snippets, not images? It makes your question more readable.

    – Darragh Enright
    Dec 31 '18 at 16:57
















-2















guys please help me to understand these code



in picture 1 router is calling with info method



as you can see in AccountController there is already info() is present then why __call() this magic function is calling



and what are these parameters is $this->request ,$this->response



we can save all data like



$request = $args[0]; $response = $args[1]; $attributes = $args[2];



why $this-> syntex is use
what is the meaning of this line $this->$name();



Router.php



<?php

$app->get('/account', 'AppControllerAccountController:info');

?>


AccountController.php



<?php
/**
* AccountController
* @package Controllers
*/
namespace AppController;


final class AccountController extends AppCoreController
{

protected function info()
{

echo $this->client_id;

}
}


Controller.php



 <?php

namespace AppCore;


class Controller
{


public function __call($name,$args) { //line 25
//echo "Call method : ".$name;
$this->request = $args[0];
$this->response = $args[1];
$this->attributes = $args[2];

//print_r($this->attributes);
$this->client_id = $this->request->getAttribute("client_id");



$this->$name();

}

}


?>









share|improve this question




















  • 2





    Hi Kershav - can you edit your question to include code snippets, not images? It makes your question more readable.

    – Darragh Enright
    Dec 31 '18 at 16:57














-2












-2








-2


1






guys please help me to understand these code



in picture 1 router is calling with info method



as you can see in AccountController there is already info() is present then why __call() this magic function is calling



and what are these parameters is $this->request ,$this->response



we can save all data like



$request = $args[0]; $response = $args[1]; $attributes = $args[2];



why $this-> syntex is use
what is the meaning of this line $this->$name();



Router.php



<?php

$app->get('/account', 'AppControllerAccountController:info');

?>


AccountController.php



<?php
/**
* AccountController
* @package Controllers
*/
namespace AppController;


final class AccountController extends AppCoreController
{

protected function info()
{

echo $this->client_id;

}
}


Controller.php



 <?php

namespace AppCore;


class Controller
{


public function __call($name,$args) { //line 25
//echo "Call method : ".$name;
$this->request = $args[0];
$this->response = $args[1];
$this->attributes = $args[2];

//print_r($this->attributes);
$this->client_id = $this->request->getAttribute("client_id");



$this->$name();

}

}


?>









share|improve this question
















guys please help me to understand these code



in picture 1 router is calling with info method



as you can see in AccountController there is already info() is present then why __call() this magic function is calling



and what are these parameters is $this->request ,$this->response



we can save all data like



$request = $args[0]; $response = $args[1]; $attributes = $args[2];



why $this-> syntex is use
what is the meaning of this line $this->$name();



Router.php



<?php

$app->get('/account', 'AppControllerAccountController:info');

?>


AccountController.php



<?php
/**
* AccountController
* @package Controllers
*/
namespace AppController;


final class AccountController extends AppCoreController
{

protected function info()
{

echo $this->client_id;

}
}


Controller.php



 <?php

namespace AppCore;


class Controller
{


public function __call($name,$args) { //line 25
//echo "Call method : ".$name;
$this->request = $args[0];
$this->response = $args[1];
$this->attributes = $args[2];

//print_r($this->attributes);
$this->client_id = $this->request->getAttribute("client_id");



$this->$name();

}

}


?>






php oop call slim magic-function






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 17:06







Keshav Sinha

















asked Dec 31 '18 at 16:51









Keshav SinhaKeshav Sinha

12




12








  • 2





    Hi Kershav - can you edit your question to include code snippets, not images? It makes your question more readable.

    – Darragh Enright
    Dec 31 '18 at 16:57














  • 2





    Hi Kershav - can you edit your question to include code snippets, not images? It makes your question more readable.

    – Darragh Enright
    Dec 31 '18 at 16:57








2




2





Hi Kershav - can you edit your question to include code snippets, not images? It makes your question more readable.

– Darragh Enright
Dec 31 '18 at 16:57





Hi Kershav - can you edit your question to include code snippets, not images? It makes your question more readable.

– Darragh Enright
Dec 31 '18 at 16:57












2 Answers
2






active

oldest

votes


















0














Router.php called your info() method on AccountController.php
But your method is protected and info() method not accessible out of the class
so __call() magic method has been called with $name and $args parameters.



$name => value is method name. "info".

$args => value array of response,request,attributes



$this => It's a reference to the current object, it's most commonly used in the object-oriented code.
What does the variable $this mean in PHP?



request,response,attributes,client_id they are variables of the controller class and accessible on each method of controller class children. like $this->client_id in your AccountController class.



    $this->request = $args[0];
$this->response = $args[1];
$this->attributes = $args[2];
$this->client_id = $this->request->getAttribute("client_id");


$this->$name(); This dymnaic way for call the methods.



PHP OOP






share|improve this answer































    0














    $this refers to itself and $this->$name();



    will calling method to your function that received as $name in __call() function






    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53989670%2fslim-routing-and-controller-how-this-call-function-is-calling-from-route-and%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Router.php called your info() method on AccountController.php
      But your method is protected and info() method not accessible out of the class
      so __call() magic method has been called with $name and $args parameters.



      $name => value is method name. "info".

      $args => value array of response,request,attributes



      $this => It's a reference to the current object, it's most commonly used in the object-oriented code.
      What does the variable $this mean in PHP?



      request,response,attributes,client_id they are variables of the controller class and accessible on each method of controller class children. like $this->client_id in your AccountController class.



          $this->request = $args[0];
      $this->response = $args[1];
      $this->attributes = $args[2];
      $this->client_id = $this->request->getAttribute("client_id");


      $this->$name(); This dymnaic way for call the methods.



      PHP OOP






      share|improve this answer




























        0














        Router.php called your info() method on AccountController.php
        But your method is protected and info() method not accessible out of the class
        so __call() magic method has been called with $name and $args parameters.



        $name => value is method name. "info".

        $args => value array of response,request,attributes



        $this => It's a reference to the current object, it's most commonly used in the object-oriented code.
        What does the variable $this mean in PHP?



        request,response,attributes,client_id they are variables of the controller class and accessible on each method of controller class children. like $this->client_id in your AccountController class.



            $this->request = $args[0];
        $this->response = $args[1];
        $this->attributes = $args[2];
        $this->client_id = $this->request->getAttribute("client_id");


        $this->$name(); This dymnaic way for call the methods.



        PHP OOP






        share|improve this answer


























          0












          0








          0







          Router.php called your info() method on AccountController.php
          But your method is protected and info() method not accessible out of the class
          so __call() magic method has been called with $name and $args parameters.



          $name => value is method name. "info".

          $args => value array of response,request,attributes



          $this => It's a reference to the current object, it's most commonly used in the object-oriented code.
          What does the variable $this mean in PHP?



          request,response,attributes,client_id they are variables of the controller class and accessible on each method of controller class children. like $this->client_id in your AccountController class.



              $this->request = $args[0];
          $this->response = $args[1];
          $this->attributes = $args[2];
          $this->client_id = $this->request->getAttribute("client_id");


          $this->$name(); This dymnaic way for call the methods.



          PHP OOP






          share|improve this answer













          Router.php called your info() method on AccountController.php
          But your method is protected and info() method not accessible out of the class
          so __call() magic method has been called with $name and $args parameters.



          $name => value is method name. "info".

          $args => value array of response,request,attributes



          $this => It's a reference to the current object, it's most commonly used in the object-oriented code.
          What does the variable $this mean in PHP?



          request,response,attributes,client_id they are variables of the controller class and accessible on each method of controller class children. like $this->client_id in your AccountController class.



              $this->request = $args[0];
          $this->response = $args[1];
          $this->attributes = $args[2];
          $this->client_id = $this->request->getAttribute("client_id");


          $this->$name(); This dymnaic way for call the methods.



          PHP OOP







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 31 '18 at 17:56









          Mohsen HosseiniMohsen Hosseini

          312




          312

























              0














              $this refers to itself and $this->$name();



              will calling method to your function that received as $name in __call() function






              share|improve this answer






























                0














                $this refers to itself and $this->$name();



                will calling method to your function that received as $name in __call() function






                share|improve this answer




























                  0












                  0








                  0







                  $this refers to itself and $this->$name();



                  will calling method to your function that received as $name in __call() function






                  share|improve this answer















                  $this refers to itself and $this->$name();



                  will calling method to your function that received as $name in __call() function







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 4 at 6:38









                  Thilina Nakkawita

                  9191228




                  9191228










                  answered Jan 4 at 3:46









                  RahulRahul

                  1




                  1






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53989670%2fslim-routing-and-controller-how-this-call-function-is-calling-from-route-and%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Monofisismo

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas