locke1994
asked on
included code inside class, code needed outside
In Router, in a method, in an included file is the controller code. In the model and in the view, I need access to the Controller's properties and methods. In Router, in an other method, I want to return a controller object to the model and the view. What now???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
yes, have some syntax or typing error in my code
i directly typed in notepad without testing
i directly typed in notepad without testing
I'm with Brian - I'm not really sure I understand your question either and if you want to rephrase it maybe we can help better.
Here is a simplified teaching example of how to use public and private properties and methods. You can install it and run it to see how it works. If you have any questions, please let me know.
Best, ~Ray
Here is a simplified teaching example of how to use public and private properties and methods. You can install it and run it to see how it works. If you have any questions, please let me know.
Best, ~Ray
<?php // RAY_oop_vars.php
error_reporting(E_ALL);
// DECLARE THE CLASS
Class MyOOP
{
public $my_public_var = 'open';
private $my_privat_var;
// DECLARE THE CONSTRUCTOR
public function __construct()
{
$this->my_privat_var = 'closed';
}
// DECLARE A FUNCTION
public function show_vars()
{
echo "<br/>\n";
echo "<br/>PUBLIC $this->my_public_var \n";
echo "<br/>PRIVAT $this->my_privat_var \n";
}
// DECLARE ANOTHER FUNCTION
public function set_privat($value)
{
$this->my_privat_var = $value;
}
// END CLASS DECLARATION
}
// INSTANTIATE THE CLASS AND SHOW THE INITIAL VALUES OF VARIABLES
$a = new MyOOP;
$a->show_vars();
// SET A PRIVATE VARIABLE VIA THE FUNCTION
$a->set_privat('NewValue');
// SET A PUBLIC VARIABLE DIRECTLY
$a->my_public_var = 'Cheese';
// SEE THE NEW VALUES
$a->show_vars();
// DUMP THE VALUES FROM THE OBJECT
echo "<pre>";
var_dump($a);
// TRY TO SET A PRIVATE VARIABLE THE WRONG WAY
$a->my_privat_var = 'Beer';
I'm mystified. Can you please tell us a little more about the question and why you accepted that answer? Thanks, ~Ray
ASKER
I didn't want to delete the question and I thought the answer was probably right.
class ModelClass {
private = $parent;
change it to
class ModelClass {
private $parent;