Yii Framework Forum: extend CWebApplication - Yii Framework Forum

Jump to content

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

extend CWebApplication Rate Topic: -----

#1 User is offline   vassy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 14-October 09

Posted 28 January 2010 - 05:46 AM

Hi.

I've gone through all cookbook articles and docs and just don't get it - how do I extend CWebApplication?
I have created a new class 'MyWebApplication' that extends CWebApplication and stored it in protected/components
I have modified index.php, so it includes my custom yii.php, which extends YiiBase and has createWebApplication overriden:

public static function createWebApplication($config=null)
	{
		return self::createApplication('MyWebApplication',$config);
	}


But now I get this error:
Warning: YiiBase::include(MyWebApplication.php) [function.YiiBase-include]: failed to open stream...
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,991
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 28 January 2010 - 06:42 AM

You don't need to override YiiBase. Why don't you try this in your index.php?

Yii::createApplication('MyWebApplication',$config)->run();

0

#3 User is offline   vassy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 14-October 09

Posted 28 January 2010 - 10:09 AM

Great advise, thank you.

It has saved me from YiiBase override, but it still reports the same error.
Should I forcibly include MyWebApplication.php ?
0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,748
  • Joined: 04-October 08
  • Location:DC, USA

Posted 28 January 2010 - 10:35 AM

Yes, you should explicitly include this class file because this is more like a bootstrap class.
0

#5 User is offline   notzippy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 06-October 08

Posted 28 January 2010 - 11:56 AM

Just for completeness sake, here is an example of index.php rewritten for a custom app
$yii='../../yii/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

// remove the following line when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);

// Check access
require_once($yii);

require_once(dirname(__FILE__).'/protected/config/CMSApplication.php');
$app = new CMSApplication($config);
$app->run();

0

#6 User is offline   RusAlex 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 23-August 10

Posted 13 January 2012 - 01:26 AM

But how can i replace CWebApplication in a unit testing ?
0

#7 User is offline   redguy 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 577
  • Joined: 02-July 10
  • Location:Central Poland

Posted 13 January 2012 - 04:33 AM

application should be instantiated in /protected/tests/bootstrap.php
just create instance of your class same way as in index.php...
red
1

#8 User is offline   pligor 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 17-January 11
  • Location:Athens, Greece

Posted 10 March 2012 - 03:12 PM

ΙΜΗΟ the CWebApplication resembles a lot like a CWebModule so it might be a good idea for a later version of Yii to have even the top level of the application as a module.
I mean to be forced by design like this!
I am not using this approach right now as extensively as I would like due to extensions that have references as 'application.models....' or 'application.controllers....'

How do you think of this idea? :)
0

#9 User is offline   raheelk2k 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 02-December 11
  • Location:Karachi

Posted 29 July 2012 - 06:23 PM

I had a case to extend the CWebApplication class but there was a caveat, the $_controller property of CWebApplication is private which must be changed to protected so that someone can extend to have their own version of CWebApplication class.

Ain't it's feasible to make all the properties of CWebApplication protected instead of private in the next version of Yii core so that anyone can extend this class easily?
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