Jump to content

Php variable in MVC


johnnyjohnny

Recommended Posts

I want to establish the similar setup Rails has, MVC, controller gets request, retrieves the model, view uses the model to output html.

 

What is the best way to pass the model variable from the controller script to the view script? (view function is called within controller script)

 

i.e.

 

//controller

<?php

$model = new User();

$model->user_name = "johnnyjohnny";

$output_html();

?>

 

//view

<?php

function output_html() {

echo "<div>$model->user_name</div>"

}

?>

 

how to pass model from controller to view?

 

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/164161-php-variable-in-mvc/
Share on other sites

If the variable isn't already defined, I'm pretty sure you need to use the __set() magic method.

 

public function __set($index, $value){
$this->$index = $value;
}

 

And what you have there doesn't look like OOP, unless you've just copied the functions from your code.

Link to comment
https://forums.phpfreaks.com/topic/164161-php-variable-in-mvc/#findComment-866010
Share on other sites

I don;t quite understand.

 

p.s. it's not OOP.

 

If the variable isn't already defined, I'm pretty sure you need to use the __set() magic method.

 

public function __set($index, $value){
$this->$index = $value;
}

 

And what you have there doesn't look like OOP, unless you've just copied the functions from your code.

Link to comment
https://forums.phpfreaks.com/topic/164161-php-variable-in-mvc/#findComment-866041
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.