Sunday, March 9, 2014

Yii-call-function-from-other-class

In this tutorial i will show how to call a method from a class

first we should import the class.

after that we should instantiate the imported class.

then we can call method via instance.

Example,


class AnotherController extends Controller
{

public function __construct($id=NULL)
{

}

public function message()
{
return 'Message from Another Controller';
}
}

?>

Above lines shows a class(Controller). assume that this class is placed in side

the contollers folder.

we want to access method "message" from another controller.

solutioin is ,

public function messageFromAnotherClass()
      {
     
  Yii::import("application.controllers.AnotherController");
  $another = new AnotherController();  
  return $message = $another->message();
      }

8 comments:



  1. Wonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!

    Online Web Development Courses

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

    rpa training in electronic city | rpa training in chennai

    rpa online training | selenium training in training

    ReplyDelete
  4. I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favourites blog site list and will be checking back soon.
    Data Science Training in Chennai | Data Science training in anna nagar
    Data Science training in chennai | Data science training in Bangalore
    Data Science training in marathahalli | Data Science training in btm

    ReplyDelete
  5. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    java training in chennai | java training in bangalore


    java training in tambaram | java training in velachery

    ReplyDelete
  6. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    Best Devops Training in pune
    Devops Training in Chennai

    ReplyDelete
  7. Very good information. Its very useful for me. We need learn from real time examples and for this we choose good training institute, we need to learn from experts . So we make use of demo classes . Recently we tried web desining demo class of Apponix Technologies.

    ReplyDelete