Yii Framework Forum: Mendapatkan Current Action didalam Widget - Yii Framework Forum

Jump to content

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

Mendapatkan Current Action didalam Widget Rate Topic: -----

#1 User is offline   __agus 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 166
  • Joined: 22-April 10
  • Location:Yogyakarta, Indonesia

Posted 02 August 2010 - 02:41 AM

Hi, para programmer Yii. Bagaimanakah caranya mendapatkan Current Action didalam Widget. Saya membuat sebuah widget "Main Banner" yang hanya tampil pada halaman index/awal saja?.
Jadi kode yg saya inginkan seperti ini:

class HookMainBanner extends CWidget
{
	public function run() {
		$this->renderContent();		
	} 

	protected function renderContent() {
            // mainbanner di render hanya jika action == site/index.
            if($action === 'site/index') {
                $this->render('mainbanner');
            }
	}	
}


Mohon bantuannya. thanks
0

#2 User is offline   fastcrash 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 10-March 10
  • Location:South Jakarta

Posted 02 August 2010 - 03:13 AM

Quote

if($action === 'site/index') {


klo url nya bukan path tinggal
echo $_GET['r'];


atau coba liat manualnya :

echo Yii::app()->baseUrl;
echo "<br />";
echo Yii::app()->urlManager->routeVar;
echo "<br />";
print_r(Yii::app()->urlManager->rules);
echo "<br />";


klo cara simpler-nya tinggal di explode
$sistem = explode('/', $_SERVER['REQUEST_URI']);
if($sistem[2] === 'site' && $sistem[3] === 'index')
{
  -- yahoo cara simpler ---
}


Posted Image
0

#3 User is offline   __agus 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 166
  • Joined: 22-April 10
  • Location:Yogyakarta, Indonesia

Posted 02 August 2010 - 09:41 PM

Makasih udah di reply..

View Postfastcrash, on 02 August 2010 - 03:13 AM, said:

klo url nya bukan path tinggal
echo $_GET['r'];


aq udah edit urlnya menjadi path.. ;D

View Postfastcrash, on 02 August 2010 - 03:13 AM, said:

atau coba liat manualnya :

echo Yii::app()->baseUrl;
echo "<br />";
yang ini keluarnya selalu rootnya "/". klo di localhost ini "/test-web".

echo Yii::app()->urlManager->routeVar;
echo "<br />";
yang ini cuma keluar variabelnya tok (r).

print_r(Yii::app()->urlManager->rules);
echo "<br />";
yg ini keluarnya g berubah2, keluarnya ini2 terus ;D :
Array
(
    [admin486] => admin486/login
    [/] => /view
    [//] => /
    [/] => /
)




View Postfastcrash, on 02 August 2010 - 03:13 AM, said:

klo cara simpler-nya tinggal di explode
$sistem = explode('/', $_SERVER['REQUEST_URI']);
if($sistem[2] === 'site' && $sistem[3] === 'index')
{
  -- yahoo cara simpler ---
}


Posted Image

kalo yang ini udah tak pakai, karena susah memakai fungsi dari Yii. :D
0

#4 User is offline   __agus 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 166
  • Joined: 22-April 10
  • Location:Yogyakarta, Indonesia

Posted 03 August 2010 - 10:29 PM

Sudah ketemu, sy tanyakan di forum General Topic dan dijawab begini:
if(Yii::app()->controller->action->id == 'index') {
    $this->render('mainbanner');
}

:D
0

Share this topic:


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

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