Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Use Widget Without View

$
0
0
Hi,
I am a newbie at Yii. I am trying to create a widget which gets the RSS feed.
It is working fine, but I want to know am I doing it the right way?

/protected/components/TestWidget.php
class TestWidget extends CWidget 
{
  public function run() 
  {
    $feed_url = '---url---';
    $feed = simplexml_load_file($feed_url);
    
    foreach($feed -> entry as $item) 
    {
       $title = $item -> title;
       $url = $item -> id;
        
       echo '<strong>Title is: </strong>' . $title . '<br />';
       echo '<strong>Url is:   </strong>' . $url . '<br />';
      
    }
   }
}


And in main.php I am simply doing.
<div ...... >
  <h4>My Widget</h4>
  <?php
    $this->widget('application.components.TestWidget');
  ?>
</div>


But on the wiki pages and on forum I have seen rendering it to the view /protected/components/views/testWidget.php file.

Thanks.

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>