Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Jan 7, 2011
0 parents commit 5237d7e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*~
*#
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# webroot_view.php #

CakePHP library for use elements and helpers under app/webroot/

## Installation ##

Put `webroot_view.php` on app/libs in your CakePHP application.

## Usage ##

If you use helper under app/webroot, add the following code.

<?php /* myapp/app/webroot/foo/bar.php */
require('../../libs/webroot_view.php');
echo $view->element('header');
echo $view->Html->link('link_title', array('controller' => 'posts', 'action' => 'index'));

### Load helpers ###

Set `$helpers` and load helpers (default: HtmlHelper and SessionHelper).

<?php /* myapp/app/webroot/foo/bar.php */
$helpers = array('Html', 'Form');
require('../../libs/webroot_view.php');
echo $view->Form->create('Foo');
echo $view->Form->input('name', array('type' => 'text'));
echo $view->Form->end('Submit');

## License ##

The MIT Lisence
37 changes: 37 additions & 0 deletions libs/webroot_view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/* put this file in yourapp/app/libs/ */
$_GET['url'] = 'favicon.ico'; // bad hack

require(dirname(__FILE__) . '/../webroot/index.php');
$config = Configure::read('App');
extract($config);
$replace = array('<', '>', '*', '\'', '"');
$base = str_replace($replace, '', dirname(env('PHP_SELF')));
if ($webroot === 'webroot') {
$base = preg_replace('/' . $webroot . '.*/', '', $base);
}
if ($dir === 'app' && $dir === basename($base)) {
$base = dirname($base);
}
$webroot = $base . '/';
Router::setRequestInfo(array(array(), array('base' => $base, 'here' => env('PHP_SELF'), 'webroot' => $webroot)));
require(dirname(__FILE__) . '/../config/routes.php');

$view = ClassRegistry::init('view');

/**
* import helper
*/
if (isset($helpers)) {
foreach ((array)$helpers as $helper) {
App::import('Helper', $helper);
$class = $helper . 'Helper';
$view->{$helper} = new $class();
}
} else {
App::import('Helper', 'Html');
App::import('Helper', 'Session');

$view->Html = new HtmlHelper();
$view->Session = new SessionHelper();
}

0 comments on commit 5237d7e

Please sign in to comment.