Problem with witget view

I want to create search widget

So I try this in '/component/Search.php'



<?php


class Search extends Portlet


{


    public $title='search';





    protected function renderContent()


    {


        $this->render('searchBar');


    }


}


in '/component/views/searchBar.php'



Hello Word!!!


in '/views/layout/homePage.php', I tried some approachs.



<?php


//Approach 1


Yii::import('application.components.*');





//Approach 2


Yii::import('application.components.Search');





//Approach 3


$this->widget('Search');





No one of above approachs show my 'Hello Word!'.

And  no error show in approach 1 & 2.

But, in approach 3, I got error like this:

Quote

include(Portlet.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

Where the problem?

Thanks a lot

May be you don't have "Portlet" class. Try using CWidget instead. In some demos the widgets extend "Portlet" class, but there is a "Portlet" class which extends "CWidget".

If you want to get it, please download it from http://code.google.c…ts/Portlet.php.

Ah… thanks for help…

I think Portlet is default Yii’s class…  ;D

Btw, I also tried CWidget with the same approachs but the 'Hello Word' doesn't show too.

Portlet isn't a default Yii class. You see it in the demo/definitive guide as a (commonly used) example of extending Yii's default classes.

For your approaches 1 and 2, as i understand it you are just importing (i.e. including) the classes in those paths, you don't actually run the widget, so there isn't any error.

On approach 3, because there isn't any include file Portlet.php in Yii (it really isn't a default Yii class), it throws that File not found error.

Edit:

A second look at your code tells me that it doesn't work even if you extend CWidget as i understand it, there's no function renderContent in CWidget.

try changing that function to

public function run()

By the way some of you might have seen me answering a few questions around these forums recently even though i'm a rather new member. I've discovered Yii not more than a month ago really, but i've already built a couple of sites for freelance clients on Yii already.

Yii really has cut my development time by more than 70%, and i find it really suits my style of thinking in terms of programming logic, so I'm trying to pay back the community by helping out people here with problems as much as i can!

Thanks Wilson, It's works now…

Yeach… Yii is a great PHP framework, even newbie in PHP like me… now I promote Yii anywhere, offline or online…