Yii Framework Forum: Rendering Several Dynamic Pages Using Single View File - Yii Framework Forum

Jump to content

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

Rendering Several Dynamic Pages Using Single View File Rate Topic: -----

#1 User is offline   Shaani 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 132
  • Joined: 17-July 12

Posted 18 September 2012 - 06:17 AM

How can I render several dynamic pages with single view file. I have LpController whose Index Action will bring records from db based on querystring parameter. For example, if I have links www.mysite.com/index.php/lp/palm_jumeirah, www.mysite.com/index.php/lp/downtown_dubai the records I need to fetch will be for these two districts without the underscore: palm jumeirah and downtown dubai.

So do I need to do all the coding in the Index action of controller ? How would I get the district palm_jumeirah for use in query ? use Yii::app()->getQueryString() ? and what do in 'urlManager' rules array ?

'<controller:\w+>/<action:\w+>'=>'<controller>/index', ??
0

#2 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 677
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 18 September 2012 - 03:22 PM

shaani sab bohat easy task hai pehli baat tu ye hai ap ko apni url design krni hai. main aik simple approach follow kron ga, ap apne controller main kuch is tarah add kr len

function actionIndex(){
  $id = end(explode("_", $_GET['page']));
  $this->render("youViewName", array(
     "page" => Page::model()->findByPk($id),
  }
}


aur phir apne view main aap page variable ka istamal kr sakte hain

$page->title;
$page->contents;


aur jab app apne pages ko link kro tu make sure k app apne table id bhi add kr end per kuch is trah
<?php $url = preg_replace(" ", "_", strtolower($page->title)); ?> // app aik helper add kr sakte hain url banaay k liye
<?php echo CHtml::link("First Page", Yii::app()->createUrl($url."_".$page->id)); ?>


aur ap ki urlManager ko kuch is tarah kr loo

Quote

'<page>'=>'<controller>/index',


and there you have it
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