Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Получить значение переменной из подключенного контроллера


GoldenScrew
 Share

Recommended Posts

Здравствуйте,

создавая свой контроллер, подключил загрузил в него уже существующий

 

Цитата

$this->load->controller('test/test');

 

в подключенном контроллере есть переменная

 

Цитата

$data['test'] = "КАКОЕ-ето значение";

 

как теперь мне получить значение переменной $data['test']?

Link to comment
Share on other sites


Если правильно понял то так:


 

$data_from_controller = $this->load->controller('test/test', true);
$data['var_from_controller'] = $data_from_controller['var_from_controller'];

 

А в test/test

в нужной функции (например index)

делаете так

public function index($return_flag) {
  ... 
  код контроллера
  ...
  if($return_flag){
  	return $data; //здесь будут все переменные контроллера или же data['переменная'];
  }
}

 

опять же все зависит от контроллера что там в коде, но примерно вот так. Если контроллер отдает сформированный шаблон с данными а вам нужны просто переменные из $data.

 

Может существует более изящный или более правильный способ, буду рад сам увидеть такой.

 

Link to comment
Share on other sites

  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.