Integrating Doctrine 2 with CodeIgniter 2

An easy to follow tutorial for integrating Doctrine 2 with CodeIgniter 2 is available at doctrine-project. Unfortunately, there are a few configuration problems which would prevent the proper loading of proxies if that configuration were to be used exactly as it is.

The problem is related to how the Proxies ClassLoader has been registered. PHP will attempt to load proxies which have the namespace Proxies from the directory {APPATH}/models/proxies/Proxies.

$proxiesClassLoader = new ClassLoader('Proxies', APPPATH.'models/proxies');
$proxiesClassLoader->register();

However, Doctrine has been configured to write proxies to the directory {APPATH}/models/proxies.

$config->setProxyDir(APPPATH.'/models/proxies');
$config->setProxyNamespace('Proxies');

Additionally, the suggested configuration registers a DefaultAnnotationDriver using the directory {APPPATH}/models/Entities which is unlikely to exist.

$driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH.'models/Entities'));
$config->setMetadataDriverImpl($driverImpl);

The configuration and instructions shown below address these issues and contain some other useful notes on the integration.
Continue reading

Rewriting WordPress from a Subdirectory

Running WordPress from a subdirectory keeps a websites root directory clean and allows easy separation from other unrelated content. However, this will result in a longer url e.g. http://ajmm.org/wordpress/ rather than http://ajmm.org/. Fortunately, it is possible to maintain this directory structure yet host WordPress using the shorter root url.

The instructions provided by the WordPress Codex provide one way to do so but the method is more complicated than necessary when considering the rewrite ability of modern webservers. Provided below are rewrite rules for Apache, IIS and nginx which do not require editing any WordPress files.

Note: all configurations assume that WordPress is hosted in a subdirectory called wordpress. Apache and IIS rules should be applied to the root folder only.

Apache .htaccess

<IfModule mod_rewrite.c>

    RewriteEngine On

    # Rewrite empty requests to the wordpress
    # index page rather than trying to display
    # a directory listing.
    RewriteRule ^$ wordpress/index.php [L]

    # Rewrite requests to the wordpress directory
    # when the resource cannot be found.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ wordpress/$1

    # Rewrite requests to the wordpress index page
    # if the resource still cannot be found.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ wordpress/index.php [L]

</IfModule>

IIS web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <directoryBrowse enabled="true" />
    <rewrite>
      <rules>
        <rule name="Wordpress Index Rewrite" stopProcessing="true">
          <match url="^$" ignoreCase="false" />
          <action type="Rewrite" url="wordpress/index.php" />
        </rule>
        <rule name="Wordpress Hard Rewrite" stopProcessing="false">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="wordpress/{R:1}" />
        </rule>
        <rule name="Wordpress Soft Rewrite" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="wordpress/index.php" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

nginx

location / {
  try_files $uri $uri/ /wordpress$uri?$args;
}

location /wordpress {
  index index.php;
  try_files $uri $uri/ /wordpress/index.php;
}