Solved

included code inside class, code needed outside

Posted on 2009-05-12
6
274 Views
Last Modified: 2012-05-06
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???
0
Comment
Question by:locke1994
6 Comments
 
LVL 7

Accepted Solution

by:
ycTIN earned 500 total points
ID: 24375409
FYI

class ModelClass {

	private = $parent;

	

	...

	public function ModelClass($_parent) {

		$this->parent = $_parent;

		

		echo $this->parent->hello();

	}

	

	...

}
 
 

class ControllerClass{
 

	...

	

	public function ControllerClass() {

		$page = new ModelClass($this);

		return $page;

	}	

	

	public function hello() {

		return "Hello";

	}

	

	...

}

Open in new window

0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 24376875
I'm not really sure I understand your question, but from looking at the code there is a syntax error in the first class that might stop it from working as you want. Where you have

class ModelClass {
        private = $parent;


change it to

class ModelClass {
        private $parent;
0
 
LVL 7

Expert Comment

by:ycTIN
ID: 24376974
yes, have some syntax or typing error in my code
i directly typed in notepad without testing
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24377357
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
<?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';

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24615016
I'm mystified.  Can you please tell us a little more about the question and why you accepted that answer?  Thanks, ~Ray
0
 

Author Comment

by:locke1994
ID: 24615050
I didn't want to delete the question and I thought the answer was probably right.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
php ssh2_scp_send 1 46
Session timeout 5 13
Bootstrap collapse causes odd behavior with php loop 7 20
How can I echo a PHP variable in AJAX function? 7 27
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now