0

I create a file in yii2 "actions", and I create a class name actionC is it possible to call function from

actions/actionC

inside a controller

my calss is

<?php

    namespace app\actions;

   class ActionC 
    {
        protected function CPost(){
            // return something
        }
    }

is it possible to call my function CPost() inside a controller actionView ?

1
  • 2
    Make it public. Commented Mar 15, 2018 at 6:41

1 Answer 1

1

Hello while your function is protected you can not call it, if you want to call a function of your class it has to be public it would be something like that

Class actionC

<?php

namespace app\actions;

class ActionC
{
    protected function CPost()
    {
        // return something
    }

    public function BPost()
    {
        // return something
    }
}

And in you View

<?php
$a=new \app\actions\ActionC();
$a->BPost();
//$a->CPost(); //this will be error because is protected 
Sign up to request clarification or add additional context in comments.

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.