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

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.

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.

That’s great and much appreciated.

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 :slight_smile:

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

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

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!

@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 :slight_smile:

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

|-…

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

Let me know if you still have problems.

@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?

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

how to load yii class into wordpress

how to call class from yii

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)

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

@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 :slight_smile:

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

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

  1. get latest yii-wordpress-integration from GitHub: https://github.com/acorncom/yii-wordpress-integration/archive/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>



  1. point your browser to www.DOMAIN.COM and install WordPress

  2. 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

  3. give write permissions to your www/data/.htaccess file and set WordPress Permalinks to suit your needs.

  4. create runtime folder into your www/protected/ folder and make sure is server writeable

  5. create assets folder into your www/data/ folder

  6. edit www/data/index.php and change $env = new Environment(); to $env = new Environment(‘DEVELOPMENT’);

  7. point your browser to www.DOMAIN.COM and Voila …

[i]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.[/i]

Thank you.

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

Has there been any updates on this? We have a yii .1.1 site like template with the login on top right… zkingdesign.com/norbert/florida/discussion.html

and will be needing to have the same header in wordpress, logged in… or if they come to the wordpress, to login there.

No, not many on my end. Haven’t yet had a client who had the need for it, so it’s mainly been prototypes :slight_smile: Let me know if you make progress on it or need help on it!

I have successfully implemented my wordpress blog in Yii for my application running in Apache server. But I want the similar application to run in nginx server. I did the exact similar things. But it did not work. I get the URL mydomain.com/blog/ correct but when I click on posts the URL is mydomain.com/blog/post1 is showing up Yii’s 404 error page with error ‘The system is unable to find the requested action “post1”’. Please help.