Yii Framework Forum: Discussion off the wiki article "Integrating Wordpress and Yii: still another approach, using Yii as the router/controller" - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Discussion off the wiki article "Integrating Wordpress and Yii: still another approach, using Yii as the router/controller" Rate Topic: -----

#21 User is offline   dualsun 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 22-March 13

Posted 26 March 2013 - 06:28 PM

View Postfr0d0z, on 26 March 2013 - 10:28 AM, said:

The short answer is absolutely. :-) And you should be able to integrate Yii/Wordpress logins if needed/desired as well. If you end up needing help integrating things, let me know, I also do this type of stuff freelance.



thanks fr0d0z !! what a relief to know that they can work together, your reply is much appreciated!
Now I can work out our plans and see which way we want to go.
0

#22 User is offline   dualsun 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 22-March 13

Posted 26 March 2013 - 06:40 PM

View Postfr0d0z, on 26 March 2013 - 10:28 AM, said:

The short answer is absolutely. :-) And you should be able to integrate Yii/Wordpress logins if needed/desired as well. If you end up needing help integrating things, let me know, I also do this type of stuff freelance.


Hi fr0d0z
I originally posted the YII and WP question in themeforest Avada theme comments section .. but the theme maker didn't know the answer so I posted it here. I've since replied to the comments board with your answer, and (I hope it is ok, please let me know) to contact you here on this forum cos you can do that type of work. If you can pm me your email I can add that to the comment so people can contact you directly .. so, I hope you can get additional work from this help you gave me.
0

#23 User is offline   acorncom 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 100
  • Joined: 25-February 11
  • Location:CO, USA

Posted 28 March 2013 - 01:37 PM

View Postdualsun, on 26 March 2013 - 06:40 PM, said:

I've since replied to the comments board with your answer, and (I hope it is ok, please let me know) to contact you here on this forum cos you can do that type of work.


That's great and much appreciated.

View Postdualsun, on 26 March 2013 - 06:40 PM, said:

If you can pm me your email I can add that to the comment so people can contact you directly .. so, I hope you can get additional work from this help you gave me.


Let's just have them contact me here if needed. I prefer not having my email out in the open for spam bots to harvest :-)

Let me know if you run into any other snags with integration stuff.
0

#24 User is offline   Jenezis 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 01-July 13

Posted 02 July 2013 - 10:59 AM

I have decision how to use Yii in Wordpress admin section.
This code you must insert in the end of file wp-admin/admin.php
$config = ABSPATH.'protected/config/admin.php'; // path to config to admin section
require(ABSPATH.'framework/YiiBase.php'); // include YiiBase
 
// overrides Yii class
class Yii extends YiiBase
{
    // override Yii autolad
    public static function autoload($className)
    {
        $wp_classes = array(
            'Translation_Entry',
            'Translations', 
            'NOOP_Translations',
            'POMO_Reader',
            'POMO_FileReader',
            'POMO_StringReader',
            'POMO_CachedFileReader',
            'POMO_CachedIntFileReader',
            'MO',
            '_WP_Editors',    
        );
        if(!in_array($className, $wp_classes))
            YiiBase::autoload($className);
    }
}

// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

// unregister default Yii autoload and register new
spl_autoload_unregister(array('YiiBase', 'autoload'));
spl_autoload_register(array('Yii','autoload'));

// create new aliases to models and components directories
Yii::setPathOfAlias( 'models', ABSPATH.'protected/models/' );
Yii::setPathOfAlias( 'components', ABSPATH.'protected/components/' );

// create Yii application, but not run it
Yii::createWebApplication($config);


Yii config file to admin section of Wordpress:
return array(
	'basePath'=>ABSPATH,
	'runtimePath' => ABSPATH.'protected/runtime',
	'name'=>'My Web Application',
	
	// autoloading model and component classes
	'import'=>array(
		'models.*',
		'components.*',
	),

	'modules'=>array(
		// TODO: include modules to admin part of WP
	),

	// application components
	'components'=>array(				
		'clientScript'=>array(
		    'class'=>'WPClientScript',
		),
		'urlManager'=>array(
		    'urlFormat'=>'path',
		    'showScriptName'=>false,
		),
		'db'=>array(
			'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
		),
		// uncomment the following to use a MySQL database
		/*
		'db'=>array(
			'connectionString' => 'mysql:host=localhost;dbname=testdrive',
			'emulatePrepare' => true,
			'username' => 'root',
			'password' => '',
			'charset' => 'utf8',
		),
		*/		
		'log'=>array(
			'class'=>'CLogRouter',
			'routes'=>array(
				array(
					'class'=>'CFileLogRoute',
					'levels'=>'error, warning',
				),				
			),
		),
	),

	// application-level parameters that can be accessed
	// using Yii::app()->params['paramName']
	'params'=>array(
		// this is used in contact page
		'adminEmail'=>'webmaster@example.com',
	),
);


And it's all... We can use Yii objects, models, components in all parts of WordPress admin
0

#25 User is offline   Dylan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 05-March 11

Posted 14 July 2013 - 07:18 AM

Does this wordpress/yii integration technique work with the latest versions of Yii and WP? On a different website I read a post from Spiros (bottom of www.linkedin.com/groups/Yii-WordPress-Integration-DEMO-ONLINE-1483367.S.157767886) where he seems to be saying that there is some problem trying to do this on the latest versions of things. Anyone know if that's true or not?

Thanks!
0

#26 User is offline   acorncom 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 100
  • Joined: 25-February 11
  • Location:CO, USA

Posted 15 July 2013 - 12:03 PM

@Dylan, not sure what would have broken with the Yii / Wordpress integration as it's pretty simple but haven't looked at it recently. Let us know if you get it working :-)
0

#27 User is offline   another-perspective 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 10-July 13

Posted 04 August 2013 - 02:28 AM

View Postacorncom, on 15 July 2013 - 12:03 PM, said:

@Dylan, not sure what would have broken with the Yii / Wordpress integration as it's pretty simple but haven't looked at it recently. Let us know if you get it working :-)


Sorry guys. I really can't seem to get this working. even using older revisions of yii and wordpress. What I have done is shown below. Hope you all can point me in the right direction. Thank you so much. Any help is appreciated. :)

Any suggestions to which version you all got it running for this integration to work?

And even if i access yiiapp/wp it throws me an error stating it cannot find a class file to include. apparently due to yii's autoloader trying to load post/1 and having 1.php as an action in WpController

I have adjusted the domain for wordpress as per tutorial: For wordpress url: yiiapp/wordpress. and site url:yiiapp

created WpController in protected/controllers, ExceptionHandler in protected/components and index.php in protected/views/wp

Just to check, is the directory supposed to be like this:

/yiiapp
|-index.php(configured with the require of wp-load and exception handler)(error if I do not remove the first '/' from '/../protected/components/ExceptionHandler.php' copied from tutorial.)
|-.htaccess(to hide the index.php)
|-protected
|-assets
|-......
/-wordpress
|-wordpress files
|-......
0

#28 User is offline   acorncom 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 100
  • Joined: 25-February 11
  • Location:CO, USA

Posted 09 August 2013 - 10:21 PM

Guys, I've just put up a Github repository to ease setting this up.

https://github.com/a...ess-integration

Let me know if you still have problems.
0

#29 User is offline   Neg 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 27-September 13

Posted 27 September 2013 - 08:30 PM

@Jenezis, with that bridge in place, how would you do something like include a widget? I'm having a hard time figuring out how to provide the right context for $this->beginWidget without giving Yii full control.

I'm trying to include Yii partials in Wordpress templates, basically.

and $this is wiped out since Yii was never run(), so something like

CBaseController::beginWidget(...)

will produce

Fatal error: Using $this when not in object context in...

did you find a way around this?
0

#30 User is offline   PHP Web Developer 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 01-October 13

Posted 03 October 2013 - 03:00 AM

please tell me that how can we call yii classes (Model, Controller classes) in wordpress
0

#31 User is offline   PHP Web Developer 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 01-October 13

Posted 03 October 2013 - 03:07 AM

how to load yii class into wordpress
0

#32 User is offline   PHP Web Developer 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 01-October 13

Posted 03 October 2013 - 03:09 AM

View PostJenezis, on 02 July 2013 - 10:59 AM, said:

I have decision how to use Yii in Wordpress admin section.
This code you must insert in the end of file wp-admin/admin.php
$config = ABSPATH.'protected/config/admin.php'; // path to config to admin section
require(ABSPATH.'framework/YiiBase.php'); // include YiiBase
 
// overrides Yii class
class Yii extends YiiBase
{
    // override Yii autolad
    public static function autoload($className)
    {
        $wp_classes = array(
            'Translation_Entry',
            'Translations', 
            'NOOP_Translations',
            'POMO_Reader',
            'POMO_FileReader',
            'POMO_StringReader',
            'POMO_CachedFileReader',
            'POMO_CachedIntFileReader',
            'MO',
            '_WP_Editors',    
        );
        if(!in_array($className, $wp_classes))
            YiiBase::autoload($className);
    }
}

// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

// unregister default Yii autoload and register new
spl_autoload_unregister(array('YiiBase', 'autoload'));
spl_autoload_register(array('Yii','autoload'));

// create new aliases to models and components directories
Yii::setPathOfAlias( 'models', ABSPATH.'protected/models/' );
Yii::setPathOfAlias( 'components', ABSPATH.'protected/components/' );

// create Yii application, but not run it
Yii::createWebApplication($config);


Yii config file to admin section of Wordpress:
return array(
	'basePath'=>ABSPATH,
	'runtimePath' => ABSPATH.'protected/runtime',
	'name'=>'My Web Application',
	
	// autoloading model and component classes
	'import'=>array(
		'models.*',
		'components.*',
	),

	'modules'=>array(
		// TODO: include modules to admin part of WP
	),

	// application components
	'components'=>array(				
		'clientScript'=>array(
		    'class'=>'WPClientScript',
		),
		'urlManager'=>array(
		    'urlFormat'=>'path',
		    'showScriptName'=>false,
		),
		'db'=>array(
			'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
		),
		// uncomment the following to use a MySQL database
		/*
		'db'=>array(
			'connectionString' => 'mysql:host=localhost;dbname=testdrive',
			'emulatePrepare' => true,
			'username' => 'root',
			'password' => '',
			'charset' => 'utf8',
		),
		*/		
		'log'=>array(
			'class'=>'CLogRouter',
			'routes'=>array(
				array(
					'class'=>'CFileLogRoute',
					'levels'=>'error, warning',
				),				
			),
		),
	),

	// application-level parameters that can be accessed
	// using Yii::app()->params['paramName']
	'params'=>array(
		// this is used in contact page
		'adminEmail'=>'webmaster@example.com',
	),
);


And it's all... We can use Yii objects, models, components in all parts of WordPress admin


how to call class from yii
0

#33 User is offline   psopacua 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 17-October 13

Posted 17 October 2013 - 04:48 AM

Hi,

First i did install the skeleton of yii. After that i installed Wordpress and followed you're article about the integration of yii and wordpress. After i followed i was getting an error about Controller.php doesn't exists so i changed the "extend Controller" part to "extend CController".

Is this the right way? (I am new to Yii Framework)
0

#34 User is offline   acorncom 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 100
  • Joined: 25-February 11
  • Location:CO, USA

Posted 18 October 2013 - 07:07 AM

Yes, if you don't have a Controller -> CController override file in your components folder, extending directly from CController works fine.
0

#35 Guest_Interboy_*

  • Group: Guests

Posted 18 October 2013 - 12:59 PM

Very cool idea!

Hope that we can extend this project into Drupal, Joomla...

I have a question about installation
Does it work well we install a new plugin from Wordpress site?
such us: Better Security, SEO Ultimate ...
Because, I can see that, there are alot of plugins that effect many functionality.
0

#36 User is offline   acorncom 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 100
  • Joined: 25-February 11
  • Location:CO, USA

Posted 18 October 2013 - 01:03 PM

@Interboy, I've got it working with a Drupal site and I know that someone else did it with Joomla.

Re: installing a new plugin with Wordpress, I haven't actually done much with the Wordpress setup (it was mainly a proof of concept), so you'll need to figure that out yourself :-)

But yes, Wordpress plugins should work. If they affect urls, it might get more complicated.
0

#37 User is offline   Bibi40k 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 16-December 10

Posted 22 April 2014 - 03:16 AM

Beginner's installing tutorial for Yii 1.1.x and latest WordPress:

1. get latest yii-wordpress-integration from GitHub: https://github.com/a...hive/master.zip
2. get latest Yii 1.1.x: http://www.yiiframework.com/download/
3. get latest WordPress: https://wordpress.org/latest.tar.gz
4. unpack and upload content of yii-wordpress-integration-master.zip into your www folder
5. unpack and upload yii-1.1.x.tar.gz content into your www/yii
6. unpack and upload latest.tar.gz content into your www/data/wordpress folder
7. change into Apache's httpd.conf file root path to www/data
<VirtualHost [b]IP[/b]:80 >
...
  DocumentRoot [b]/FULL_PATH_TO/public_html/data[/b]
  ScriptAlias /cgi-bin/ [b]/FULL_PATH_TO[/b]/public_html/data/cgi-bin/
...
</VirtualHost>

8. point your browser to www.DOMAIN.COM and install WordPress
9. log into WordPress and change Site Address (URL) from Settings/General from http://www.DOMAIN.COM/wordpress to http://www.DOMAIN.COM. Make sure WordPress Address (URL) is http://www.DOMAIN.COM/wordpress
10. give write permissions to your www/data/.htaccess file and set WordPress Permalinks to suit your needs.
11. create runtime folder into your www/protected/ folder and make sure is server writeable
12. create assets folder into your www/data/ folder
13. edit www/data/index.php and change $env = new Environment(); to $env = new Environment('DEVELOPMENT');
14. point your browser to www.DOMAIN.COM and Voila ...


Suggestions for GitHub master files:
- add runtime and assets folder
- change $env = new Environment(); to $env = new Environment('DEVELOPMENT'); or other type, otherwise we all get a blank page with no errors.


Thank you.
0

#38 User is offline   Bibi40k 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 16-December 10

Posted 22 April 2014 - 05:48 AM

How do i get Yii conditional visibility into WP menus ?

How can i make this work ?
array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)

or better how to add "$this->widget" into wp headder ?

Search also seems it is not working, any solution ?

Thanks
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • 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