What does this code means?

trowa
trowa used Ask the Experts™
on
Can someone explain this code to me?

/*CALL Controllers CLASS IF EXIST*/

			if($row){ 

				$this->load->ClassValidation = false;

				$this->className = str_replace("-",'_',$row->slug);

				$this->load->controller( $this->className );

				if(method_exists( $this->load->{$this->className}, index ))

					$this->load->{$this->className}->index($data);

				else

					$this->load->view( $row->folder.'/'.$row->goto, $data ); //default

			}

			else

				$this->load->view( $row->goto ); //!$row- page not found

Open in new window


Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ste5anSenior Developer
Commented:
It's a kind of dynamic (runtime) method invocation.

p.s. <nitpicking> you don't call classes, only instances or objects. Classes are the "template", "model" or "skeleton" of an instance or object.
Application Developer
Commented:
Obviously it is an mvc structure.
anyway, the code checks the followings :
  • if [$row] contains data
                   
  • then get the relevant class and check for specific method by index ,then load the data accordingly
                   
  • if the method doesn't exist for some reason, then load the default page
  • if the [$row] doesn't contain data, then load the not found page

Author

Commented:
Thanks for the replies, I know this is a mvc structure but I'm not sure the syntax.

For example, what's the difference between these two methods?

$this->load->{$this->className}->index($data);

vs

$this->load->view( $row->folder.'/'.$row->goto, $data ); //default

Will the method: "load" actually load something?? is there a method called as ->load in php?
M. TariqApplication Developer
Commented:
it is not a built in function obviously, rather a defined method in a class.
It's tough to know what is happening behind the hood without knowing which framework is this. However, the load->view method obviously loads the view[the representation] and serve it.

Author

Commented:
Thank you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial