pagechecker Checks whether the current page rendered is the specific page

  1. Requirements
  2. Installation
  3. Usage

This extension is a simple behavior component that is attached to your 'web application' to check whether the current page rendered is the specified page or not. Its a very simple and short yet important stuff in anyone's project. Usually we want to filter some portion in our view page or take coding decisions according to the page displayed, which you could do easily using this. This extension is basically inspired from pisfrontpage extension. It didn't worked out for me, so I have created this general extension.

Requirements

Yii 1.0 or above

Installation

  • Extract the contents of this package. Put the resulted php class file under /protected/components
  • Inside protected/config/main.php config file:
// ...
'behaviors' => array(
    'pageChecker' => array(
        'class' => 'application.components.PageChecker',
    )
),
// ...

Usage

here you want to check for the specific page rendered, place following code and pass either the following predefined strings:

-`homepage` for Hompage/frontpage, 
-`contact` for Contact Page, 
-`about` for About Us page and 
-`login` for Login page

or the controller action route itself.

if (Yii::app()->checkSpecifiedPage('<pagename or controller action route>')) {
  // do something specific for the page
}

For example to check whether the rendered page is the homepage or frontpage then check with the following code:

if (Yii::app()->checkSpecifiedPage('homepage')) {
  // do something specific for the homepage
}

Likewise for contact page, you could use

if (Yii::app()->checkSpecifiedPage('contact')) {
  // do something specific for the homepage
}

OR you could directly pass the controller action route

if (Yii::app()->checkSpecifiedPage('exampleController/exampleAction')) {
  // do something specific for the exampleAction page in the exampleController 	Controller
}
0 0
2 followers
0 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Developed by: Sharkgr8
Created on: Oct 3, 2012
Last updated: 12 years ago

Related Extensions