0
votes

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
Make it public. - Bizley

1 Answers

1
votes

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