Yii Framework Forum: How To Display Controller Action Into Theme? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Display Controller Action Into Theme? Rate Topic: -----

#1 User is offline   marvix 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 85
  • Joined: 02-August 13

Posted 14 October 2013 - 03:15 PM

Hi,

I have this action in article controller:

	public function actionList($cid){
	    $PZ = Yii::app()->params['defaultPageSize'];
     	$dataProvider=new CActiveDataProvider('Article', array('criteria'=>array(
                                                                                                    	'condition'=>'status=1 AND sticky=0 AND cid='.$cid,
                                                                                                    	'order'=>'created ASC',
                                                                                                    	), 
                                                                                                    	'pagination' => array('pageSize' => $PZ, )
                                                                                                        )
                                                                                );
		$this->render('list',array(
			'dataProvider'=>$dataProvider,
		));

	}


How I can can this action in the theme to show the result ?


THX
0

#2 User is offline   outrage 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 313
  • Joined: 10-November 09
  • Location:Blackpool, United Kingdom

Posted 14 October 2013 - 05:10 PM

Ganerally your theme is set in config/main.php like this:

return array(
    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
    'name' => 'Your App Name',
    'theme' => 'yourTheme',
    ...


You can also set the theme in your controller like this:

public function actionList($cid){
    Yii::app()->theme = 'yourTheme';
   ...

0

#3 User is offline   marvix 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 85
  • Joined: 02-August 13

Posted 14 October 2013 - 06:56 PM

I do not want to change the action theme, I need to list articles in the index page based on the category... such as:

<div class=cat1>
<?php Article::List('90');
</div>
<div class=cat2>
<?php Article::List('91');
</div>
<div class=cat3>
<?php Article::List('92');
</div>


0

#4 User is offline   marvix 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 85
  • Joined: 02-August 13

Posted 15 October 2013 - 11:06 AM

Anyone?

I need to create block design, a block will hold 5 record based on category if.
0

#5 User is offline   Arockia Johnson 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 94
  • Joined: 25-June 13

Posted 17 October 2013 - 07:24 AM

Hi,

You can add the following code directly into your themes view file ( main.php )


     Yii::app()->runController('article/List/cid/'.$yourid); //Dynamically call the category id. 



Use render partial at your action List...
Thanks & Regards,
S.A. Johnson
www.arojohnson.tk
0

#6 User is offline   marvix 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 85
  • Joined: 02-August 13

Posted 18 October 2013 - 05:59 AM

View PostArockia Johnson, on 17 October 2013 - 07:24 AM, said:

Hi,

You can add the following code directly into your themes view file ( main.php )


     Yii::app()->runController('article/List/cid/'.$yourid); //Dynamically call the category id. 



Use render partial at your action List...


it worked for me, but its render the whole theme again !

I found the solution .... in theme index :

                    $dataProvider=Article::getBlockData(101,6);
                    $data = $dataProvider->getData();
                    //Get category name
                    $Category = Category::model()->findByAttributes(array('id'=>101));
                    echo '<div class="category-name"><h4>'.$Category->name.'</h4></div>';
                    foreach($data as $i => $item){
                              //for clean result without HTML
                             Yii::app()->controller->renderPartial('_articleBlock',array('index' => $i, 'data' => $item, 'widget' => $this));
                    }


0

#7 User is offline   Arockia Johnson 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 94
  • Joined: 25-June 13

Posted 18 October 2013 - 06:36 AM

View Postmarvix, on 18 October 2013 - 05:59 AM, said:

it worked for me, but its render the whole theme again !

I found the solution .... in theme index :

                    $dataProvider=Article::getBlockData(101,6);
                    $data = $dataProvider->getData();
                    //Get category name
                    $Category = Category::model()->findByAttributes(array('id'=>101));
                    echo '<div class="category-name"><h4>'.$Category->name.'</h4></div>';
                    foreach($data as $i => $item){
                              //for clean result without HTML
                         	Yii::app()->controller->renderPartial('_articleBlock',array('index' => $i, 'data' => $item, 'widget' => $this));
                    }




Thats great marvix,

If we decided MVC structure - you may not use your $dataProvider .... and some querying strings ..at the view file...

anyway it works fine... CHEERS... MARVIX.
Thanks & Regards,
S.A. Johnson
www.arojohnson.tk
0

#8 Guest_Interboy_*

  • Group: Guests

Posted 18 October 2013 - 12:46 PM

In controller, you can change layout too.
e.g:
public $layout='column2';

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users