开发者

Custom class variables in symfony

开发者 https://www.devze.com 2023-03-08 22:21 出处:网络
I am in trouble, I have created my own class and access functions of that class in my actionindex function using myclass::myfunction(); but I saw a surprising behavior of class variables that when I a

I am in trouble, I have created my own class and access functions of that class in my actionindex function using myclass::myfunction(); but I saw a surprising behavior of class variables that when I assigned a value to one variable then all other variables are also containing that value. I want to put different value in each variable but I can't

Then I used second way of accessing class i. E .

$obj= new myclass();
$obj->myfunction();

But in that case I am unable to access public variables of class in the function, the开发者_StackOverflow中文版y are not working


in action:

public function executeFoo($request){
  $obj= new myclass();
  $this->output = $obj->myfunction();

}

in fooSuccess.php

<?php print_r($output); ?>

you also could output i right from the action:

public function executeFoo($request){
  $obj= new myclass();
  return $this->renderText($obj->myfunction());    
}
0

精彩评论

暂无评论...
验证码 换一张
取 消