How to access a controller action , from ctp file in CakePHP 3











up vote
1
down vote

favorite
1












I want to access a controller action from ctp file. Here my action name and ctp file name is different. For example I created an action in the name of tickets ,and my view ctp file name is ticket_title. How to do this ?



This is my action : ticket



class UsersController extends AppController
{
public function ticket()
{
$ticket=$this->Tickets->find('all');
$this->set(compact('ticket'));
}
}


My view ctp file : ticket_title.ctp



<?php
$this->requestAction(array('controller' => 'users', 'action' => 'ticket'));

foreach($ticket as $ticket1)
{
echo $ticket1->title."<br/>";
}


Can any one help me ?.










share|improve this question
























  • Possible duplicate: stackoverflow.com/questions/30318793/…
    – Inigo Flores
    Jan 19 '16 at 18:46















up vote
1
down vote

favorite
1












I want to access a controller action from ctp file. Here my action name and ctp file name is different. For example I created an action in the name of tickets ,and my view ctp file name is ticket_title. How to do this ?



This is my action : ticket



class UsersController extends AppController
{
public function ticket()
{
$ticket=$this->Tickets->find('all');
$this->set(compact('ticket'));
}
}


My view ctp file : ticket_title.ctp



<?php
$this->requestAction(array('controller' => 'users', 'action' => 'ticket'));

foreach($ticket as $ticket1)
{
echo $ticket1->title."<br/>";
}


Can any one help me ?.










share|improve this question
























  • Possible duplicate: stackoverflow.com/questions/30318793/…
    – Inigo Flores
    Jan 19 '16 at 18:46













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I want to access a controller action from ctp file. Here my action name and ctp file name is different. For example I created an action in the name of tickets ,and my view ctp file name is ticket_title. How to do this ?



This is my action : ticket



class UsersController extends AppController
{
public function ticket()
{
$ticket=$this->Tickets->find('all');
$this->set(compact('ticket'));
}
}


My view ctp file : ticket_title.ctp



<?php
$this->requestAction(array('controller' => 'users', 'action' => 'ticket'));

foreach($ticket as $ticket1)
{
echo $ticket1->title."<br/>";
}


Can any one help me ?.










share|improve this question















I want to access a controller action from ctp file. Here my action name and ctp file name is different. For example I created an action in the name of tickets ,and my view ctp file name is ticket_title. How to do this ?



This is my action : ticket



class UsersController extends AppController
{
public function ticket()
{
$ticket=$this->Tickets->find('all');
$this->set(compact('ticket'));
}
}


My view ctp file : ticket_title.ctp



<?php
$this->requestAction(array('controller' => 'users', 'action' => 'ticket'));

foreach($ticket as $ticket1)
{
echo $ticket1->title."<br/>";
}


Can any one help me ?.







model-view-controller action cakephp-3.x ctp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 '16 at 17:53

























asked Jan 19 '16 at 17:35









Balasuresh Asaithambi

347314




347314












  • Possible duplicate: stackoverflow.com/questions/30318793/…
    – Inigo Flores
    Jan 19 '16 at 18:46


















  • Possible duplicate: stackoverflow.com/questions/30318793/…
    – Inigo Flores
    Jan 19 '16 at 18:46
















Possible duplicate: stackoverflow.com/questions/30318793/…
– Inigo Flores
Jan 19 '16 at 18:46




Possible duplicate: stackoverflow.com/questions/30318793/…
– Inigo Flores
Jan 19 '16 at 18:46












3 Answers
3






active

oldest

votes

















up vote
2
down vote













Finally , it works by using render() method.
In my action:



public function ticket()
{
$this->loadModel('Tickets');
$ticket=$this->Tickets->find('all');
$this->set(compact('ticket'));
$this->render('ticket_title');
}


And this is my ticket_title.ctp



<?php
foreach($ticket as $ticket1)
{
echo $ticket1->title."<br/>";
}





share|improve this answer




























    up vote
    0
    down vote













    Yes, its working in CTP of Cake PHP 3 . You can use this object in any other controller or in ctp file where needed



    (in case of controller)



    use AppControllerControllerName;

    $ControllerNameObj = new ControllerName;

    $ControllerNameObj->functionName();


    (in case of ctp file)



    $abcObj = new AppControllerHomeController;

    $fetchdetail = $abcObj->ControllerfunctionName($parameter1, $parameter2);





    share|improve this answer






























      up vote
      0
      down vote













      you can use this object in any other controller or in ctp file where needed



      (in case of controller)



      use AppControllerControllerName;

      $ControllerNameObj = new ControllerName;

      $ControllerNameObj->functionName();


      (in case of ctp file)



      $abcObj = new AppControllerHomeController; 

      $fetchdetail = $abcObj->ControllerfunctionName($parameter1, $parameter2);





      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',
        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%2f34883390%2fhow-to-access-a-controller-action-from-ctp-file-in-cakephp-3%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        2
        down vote













        Finally , it works by using render() method.
        In my action:



        public function ticket()
        {
        $this->loadModel('Tickets');
        $ticket=$this->Tickets->find('all');
        $this->set(compact('ticket'));
        $this->render('ticket_title');
        }


        And this is my ticket_title.ctp



        <?php
        foreach($ticket as $ticket1)
        {
        echo $ticket1->title."<br/>";
        }





        share|improve this answer

























          up vote
          2
          down vote













          Finally , it works by using render() method.
          In my action:



          public function ticket()
          {
          $this->loadModel('Tickets');
          $ticket=$this->Tickets->find('all');
          $this->set(compact('ticket'));
          $this->render('ticket_title');
          }


          And this is my ticket_title.ctp



          <?php
          foreach($ticket as $ticket1)
          {
          echo $ticket1->title."<br/>";
          }





          share|improve this answer























            up vote
            2
            down vote










            up vote
            2
            down vote









            Finally , it works by using render() method.
            In my action:



            public function ticket()
            {
            $this->loadModel('Tickets');
            $ticket=$this->Tickets->find('all');
            $this->set(compact('ticket'));
            $this->render('ticket_title');
            }


            And this is my ticket_title.ctp



            <?php
            foreach($ticket as $ticket1)
            {
            echo $ticket1->title."<br/>";
            }





            share|improve this answer












            Finally , it works by using render() method.
            In my action:



            public function ticket()
            {
            $this->loadModel('Tickets');
            $ticket=$this->Tickets->find('all');
            $this->set(compact('ticket'));
            $this->render('ticket_title');
            }


            And this is my ticket_title.ctp



            <?php
            foreach($ticket as $ticket1)
            {
            echo $ticket1->title."<br/>";
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 20 '16 at 8:25









            Balasuresh Asaithambi

            347314




            347314
























                up vote
                0
                down vote













                Yes, its working in CTP of Cake PHP 3 . You can use this object in any other controller or in ctp file where needed



                (in case of controller)



                use AppControllerControllerName;

                $ControllerNameObj = new ControllerName;

                $ControllerNameObj->functionName();


                (in case of ctp file)



                $abcObj = new AppControllerHomeController;

                $fetchdetail = $abcObj->ControllerfunctionName($parameter1, $parameter2);





                share|improve this answer



























                  up vote
                  0
                  down vote













                  Yes, its working in CTP of Cake PHP 3 . You can use this object in any other controller or in ctp file where needed



                  (in case of controller)



                  use AppControllerControllerName;

                  $ControllerNameObj = new ControllerName;

                  $ControllerNameObj->functionName();


                  (in case of ctp file)



                  $abcObj = new AppControllerHomeController;

                  $fetchdetail = $abcObj->ControllerfunctionName($parameter1, $parameter2);





                  share|improve this answer

























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Yes, its working in CTP of Cake PHP 3 . You can use this object in any other controller or in ctp file where needed



                    (in case of controller)



                    use AppControllerControllerName;

                    $ControllerNameObj = new ControllerName;

                    $ControllerNameObj->functionName();


                    (in case of ctp file)



                    $abcObj = new AppControllerHomeController;

                    $fetchdetail = $abcObj->ControllerfunctionName($parameter1, $parameter2);





                    share|improve this answer














                    Yes, its working in CTP of Cake PHP 3 . You can use this object in any other controller or in ctp file where needed



                    (in case of controller)



                    use AppControllerControllerName;

                    $ControllerNameObj = new ControllerName;

                    $ControllerNameObj->functionName();


                    (in case of ctp file)



                    $abcObj = new AppControllerHomeController;

                    $fetchdetail = $abcObj->ControllerfunctionName($parameter1, $parameter2);






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 17 at 17:05









                    Agilanbu

                    867617




                    867617










                    answered Nov 17 at 7:01









                    Gaurav Singhal

                    1




                    1






















                        up vote
                        0
                        down vote













                        you can use this object in any other controller or in ctp file where needed



                        (in case of controller)



                        use AppControllerControllerName;

                        $ControllerNameObj = new ControllerName;

                        $ControllerNameObj->functionName();


                        (in case of ctp file)



                        $abcObj = new AppControllerHomeController; 

                        $fetchdetail = $abcObj->ControllerfunctionName($parameter1, $parameter2);





                        share|improve this answer



























                          up vote
                          0
                          down vote













                          you can use this object in any other controller or in ctp file where needed



                          (in case of controller)



                          use AppControllerControllerName;

                          $ControllerNameObj = new ControllerName;

                          $ControllerNameObj->functionName();


                          (in case of ctp file)



                          $abcObj = new AppControllerHomeController; 

                          $fetchdetail = $abcObj->ControllerfunctionName($parameter1, $parameter2);





                          share|improve this answer

























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            you can use this object in any other controller or in ctp file where needed



                            (in case of controller)



                            use AppControllerControllerName;

                            $ControllerNameObj = new ControllerName;

                            $ControllerNameObj->functionName();


                            (in case of ctp file)



                            $abcObj = new AppControllerHomeController; 

                            $fetchdetail = $abcObj->ControllerfunctionName($parameter1, $parameter2);





                            share|improve this answer














                            you can use this object in any other controller or in ctp file where needed



                            (in case of controller)



                            use AppControllerControllerName;

                            $ControllerNameObj = new ControllerName;

                            $ControllerNameObj->functionName();


                            (in case of ctp file)



                            $abcObj = new AppControllerHomeController; 

                            $fetchdetail = $abcObj->ControllerfunctionName($parameter1, $parameter2);






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 19 at 7:18









                            Agilanbu

                            867617




                            867617










                            answered Jun 4 at 10:38









                            Mohit saini

                            11




                            11






























                                 

                                draft saved


                                draft discarded



















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34883390%2fhow-to-access-a-controller-action-from-ctp-file-in-cakephp-3%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

                                Costa Masnaga

                                Fotorealismo

                                Sidney Franklin