From 5000fd4032b7d4df26d4865cad5c8c163e8402f5 Mon Sep 17 00:00:00 2001 From: mwhitneysdsu Date: Fri, 8 May 2015 08:08:49 -0700 Subject: [PATCH 01/11] 0.7.4 dev --- application/config/constants.php | 2 +- bonfire/docs/changelog.md | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/application/config/constants.php b/application/config/constants.php index ca94609a4..61b6c9ab1 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -93,7 +93,7 @@ // Bonfire-specific Constants // ----------------------------------------------------------------------------- -define('BONFIRE_VERSION', 'v0.7.3'); +define('BONFIRE_VERSION', 'v0.7.4-dev'); // ----------------------------------------------------------------------------- // The 'App Area' allows you to specify the base folder used for all of the contexts diff --git a/bonfire/docs/changelog.md b/bonfire/docs/changelog.md index 85614df8a..955989c6b 100644 --- a/bonfire/docs/changelog.md +++ b/bonfire/docs/changelog.md @@ -2,6 +2,18 @@ ## Under development +### 0.7.4 + +#### New Features: + +#### Closes Issues: + +#### Additional Changes: + +#### Known Issues: + +## Released versions + ### 0.7.3 #### New Features: @@ -43,8 +55,6 @@ #### Known Issues: -## Released versions - ### 0.7.2 #### New Features: From b54190be314332d5db7f972f51ccde9540b911a9 Mon Sep 17 00:00:00 2001 From: mwhitneysdsu Date: Wed, 13 May 2015 06:13:14 -0700 Subject: [PATCH 02/11] Fix #1112 - Can't login to site when offline in CI3 Thanks to @markbratanov for possibly reporting this issue, or at least reporting an issue which reminded me to test this under CI3. --- application/hooks/App_hooks.php | 3 ++- bonfire/docs/changelog.md | 1 + bonfire/docs/upgrade/074.md | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 bonfire/docs/upgrade/074.md diff --git a/application/hooks/App_hooks.php b/application/hooks/App_hooks.php index a4430f995..3158ed08a 100644 --- a/application/hooks/App_hooks.php +++ b/application/hooks/App_hooks.php @@ -133,7 +133,8 @@ public function checkSiteStatus() } if (! $this->ci->auth->has_permission('Site.Signin.Offline')) { - if (! in_array($this->ci->uri->ruri_string(), $this->allowOffline)) { + $ruriString = '/' . ltrim(str_replace($this->ci->router->directory, '', $this->ci->uri->ruri_string()), '/'); + if (! in_array($ruriString, $this->allowOffline)) { $offlineReason = $this->ci->settings_lib->item('site.offline_reason'); include (APPPATH . 'errors/offline.php'); die(); diff --git a/bonfire/docs/changelog.md b/bonfire/docs/changelog.md index 955989c6b..5cde4f9c5 100644 --- a/bonfire/docs/changelog.md +++ b/bonfire/docs/changelog.md @@ -7,6 +7,7 @@ #### New Features: #### Closes Issues: +* #1112 Can't login to site when offline in CI3 #### Additional Changes: diff --git a/bonfire/docs/upgrade/074.md b/bonfire/docs/upgrade/074.md new file mode 100644 index 000000000..86ab9cbf2 --- /dev/null +++ b/bonfire/docs/upgrade/074.md @@ -0,0 +1,5 @@ +# Upgrading Bonfire + +## 0.7.3 to 0.7.4 + +1. Update `/application/hooks/App_hooks.php`. From 62e6fc9639790b3936867cfc5ac5d68a0cc7ab73 Mon Sep 17 00:00:00 2001 From: mwhitneysdsu Date: Wed, 13 May 2015 13:30:41 -0700 Subject: [PATCH 03/11] Fix #1113 [Builder] syntax-error on required field I have no doubt missed further errors on this, but at least checkboxes and inputs should be built properly, now. --- bonfire/docs/changelog.md | 1 + bonfire/modules/builder/views/files/view_default.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bonfire/docs/changelog.md b/bonfire/docs/changelog.md index 5cde4f9c5..5a1842253 100644 --- a/bonfire/docs/changelog.md +++ b/bonfire/docs/changelog.md @@ -7,6 +7,7 @@ #### New Features: #### Closes Issues: +* #1113 Syntax error in the builder-built view (when adding a required input field) * #1112 Can't login to site when offline in CI3 #### Additional Changes: diff --git a/bonfire/modules/builder/views/files/view_default.php b/bonfire/modules/builder/views/files/view_default.php index 5969e8fbb..1c1ad0723 100644 --- a/bonfire/modules/builder/views/files/view_default.php +++ b/bonfire/modules/builder/views/files/view_default.php @@ -88,7 +88,7 @@
@@ -117,7 +117,7 @@ $viewFields .= PHP_EOL . "
\"> - 'control-label')); ?> + 'control-label')); ?>
{$field_name}) ? \${$module_name_lower}->{$field_name} : ''); ?>\" /> From d2f9c75762b3b5a080a35ac537b556a2c08f87b5 Mon Sep 17 00:00:00 2001 From: mwhitneysdsu Date: Wed, 13 May 2015 13:32:55 -0700 Subject: [PATCH 04/11] update upgrade docs for 0.7.4 to reflect previous change --- bonfire/docs/upgrade/074.md | 1 + 1 file changed, 1 insertion(+) diff --git a/bonfire/docs/upgrade/074.md b/bonfire/docs/upgrade/074.md index 86ab9cbf2..9d2c9f107 100644 --- a/bonfire/docs/upgrade/074.md +++ b/bonfire/docs/upgrade/074.md @@ -3,3 +3,4 @@ ## 0.7.3 to 0.7.4 1. Update `/application/hooks/App_hooks.php`. +2. Update `/bonfire/modules/builder/`. From ef47a48bb9224213993d687dda6ccdf731571dd7 Mon Sep 17 00:00:00 2001 From: mwhitneysdsu Date: Wed, 20 May 2015 14:32:46 -0700 Subject: [PATCH 05/11] Add upgrade docs to toc --- bonfire/docs/_toc.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bonfire/docs/_toc.ini b/bonfire/docs/_toc.ini index 04a8c6506..607227658 100644 --- a/bonfire/docs/_toc.ini +++ b/bonfire/docs/_toc.ini @@ -7,6 +7,8 @@ developer/tut_blog = Simple Blog Tutorial developer/changelog = Change Log [Upgrade Notes] +developer/upgrade/074 = 0.7.3 to 0.7.4 +developer/upgrade/073 = 0.7.2 to 0.7.3 developer/upgrade/072 = 0.7.1 to 0.7.2 developer/upgrade/071 = 0.7.0 to 0.7.1 From c81ac1d985e9fe4a8e908e6ceb09bb0970e66ae3 Mon Sep 17 00:00:00 2001 From: mwhitneysdsu Date: Wed, 20 May 2015 14:34:53 -0700 Subject: [PATCH 06/11] Add themeView() method to Template library - The themeView() method performs the functionality previously only found in the theme_view() helper function. - The helper function is now a shortcut to the themeView() method. - Cleanup for some of the documentation related to the library. --- bonfire/docs/layouts_and_views.md | 358 ++++++++++++++++-------------- bonfire/docs/template.md | 15 +- bonfire/libraries/Template.php | 70 +++--- 3 files changed, 248 insertions(+), 195 deletions(-) diff --git a/bonfire/docs/layouts_and_views.md b/bonfire/docs/layouts_and_views.md index 3ef7b6cce..145157e3e 100644 --- a/bonfire/docs/layouts_and_views.md +++ b/bonfire/docs/layouts_and_views.md @@ -2,25 +2,34 @@ ## Overview: How the Pieces Fit Together -This guide covers how Bonfire handles rendering views within your application. It presents the relationship between standard CodeIgniter views and how they fit into the overall Theme. +This guide covers how Bonfire handles rendering views within your application. +It presents the relationship between standard CodeIgniter views and how they fit into the overall Theme. -In a straight CodeIgniter application you might be used to having a view for your header and a view for your footer. Then, in each view file, you would use `$this->load->view('header')` to keep a consistent layout across your site. This works well, and is one of the fastest options available to you. But it's not the most efficient or flexible from a developer's viewpoint. +In a straight CodeIgniter application you might be used to having a view for your header and a view for your footer. +Then, in each view file, you would use `$this->load->view('header')` to keep a consistent layout across your site. +This works well, and is one of the fastest options available to you. +But it's not the most efficient or flexible from a developer's viewpoint. -Bonfire uses Themes, which you'll be accustomed to using in nearly any CMS out there. Each theme contains one or more layouts (one-column, two-column, blog, etc) as well as any assets (like CSS or Javascript files) that the theme might need. A single command in your controller is all that is needed to make this work. +Bonfire uses Themes, which you'll be accustomed to using in nearly any CMS out there. +Each theme contains one or more layouts (one-column, two-column, blog, etc) as well as any assets (like CSS or Javascript files) that the theme might need. +A single command in your controller is all that is needed to make this work. Views are exactly what you are accustomed to working with, but follow a simple convention that keeps things consistent among all of the developers on your team, and keeps things simple and organized. - ## Views -Views in Bonfire are the same views that are available within stock CodeIgniter. They are just organized to take advantage of conventions that make keeping which view belongs to which method much simpler and consistent across projects and between co-workers. Since most of the work that you will be doing will be focused within modules, all of the examples will use a `blog` module as an example. However, these same principles apply directly to the `application/views` folder itself. +Views in Bonfire are the same views that are available within stock CodeIgniter. +They are just organized to take advantage of conventions that make keeping which view belongs to which method much simpler and consistent across projects and between co-workers. +Since most of the work that you will be doing will be focused within modules, all of the examples will use a `blog` module as an example. +However, these same principles apply directly to the `application/views` folder itself. ### Using `render` -Wherever you would have used CodeIgniter's `$this->load->view()` previously, you should use `Template::render()` instead. It displays a view, wrapped within your themed layout files, checks if it's an AJAX or mobile request, and handles it all without you having to do much. At its simplest, all you have to do to display a fully-themed page from within your controller is: - +Wherever you would have used CodeIgniter's `$this->load->view()` previously, you should use `Template::render()` instead. +It displays a view, wrapped within your themed layout files, checks if it's an AJAX or mobile request, and handles it all without you having to do much. +At its simplest, all you have to do to display a fully-themed page from within your controller is: class Blog extends Front_Controller { @@ -34,51 +43,71 @@ Wherever you would have used CodeIgniter's `$this->load->view()` previously, you ### Rendering a Method's View -Bonfire's template system favors certain conventions in order to keep your project organized and make your job easier. When you use the `render()` method it looks for a view with the same name as the active method. - -All public context views (those front-facing pages) will be found in your module's `/view` folder. All other contexts (content, settings, etc) should have a folder matching the context name, and the view would be inside of that folder. +Bonfire's template system favors certain conventions in order to keep your project organized and make your job easier. +When you use the `render()` method it looks for a view with the same name as the active method. +All public context views (those front-facing pages) will be found in your module's `/view` folder. +All other contexts (content, settings, etc) should have a folder matching the context name, and the view would be inside of that folder. /** * Public Context for Blog Module - * - * View would be found at: - * module_name/ - * views/ - * index.php */ class Blog extends Front_Controller { + /** + * View would be found at: + * /public/themes/{currentTheme}/blog/index.php + * OR + * /application/modules/blog/views/index.php + */ public function index() { Template::render(); } - } + /** + * View would be found at: + * /public/themes/{currentTheme}/blog/test.php + * OR + * /application/modules/blog/views/test.php + */ + public function test() + { + Template::render(); + } + } /** - * Settings Context - * - * View would be found at: - * module_name/ - * views/ - * settings/ - * index.php + * Settings Context for Blog Module */ class Settings extends Admin_Controller { + /** + * View would be found at: + * /application/modules/blog/views/settings/index.php + */ public function index() { Template::render(); } - } + /** + * View would be found at: + * /application/modules/blog/views/settings/test.php + */ + public function test() + { + Template::render(); + } + } ### Rendering an Arbitrary View -Sometimes you will need to use a different view than what Bonfire defaults to, such as when you want to share a form between your `create` and `edit` methods. This can be handled by using the `set_view()` method of the Template library. The only parameter is the name of the view file to display. The view name is relative to the module's view folder. - +Sometimes you will need to use a different view than what Bonfire defaults to, such as when you want to share a form between your `create` and `edit` methods. +This can be handled by using the `set_view()` method of the Template library. +The only parameter is the name of the view file to display. +The view name is relative to the module's view folder. class Settings extends Admin_Controller { @@ -89,88 +118,147 @@ Sometimes you will need to use a different view than what Bonfire defaults to, s } } - ### Rendering Theme Views -Often you will want to display one of the files from your theme within one of your view files. This is most often done within one of your layouts (see below) but can be done from within any view. You would accomplish this by using the `theme_view()` helper function. You don't need to load any helpers to make this happen, it is ready for you when your Template library is loaded. - -The first parameter is the name of the view to display. This view is relative to your active theme's folder. +Often you will want to display one of the files from your theme within one of your view files. +This is most often done within one of your layouts (see below) but can be done from within any view. +You would accomplish this by using the `themeView()` method of the Template library or the `theme_view()` helper function. +You don't need to load a helper file to make the helper function available, it is ready when the Template library is loaded. +The helper function is just a short-cut to the Template method, so the parameters and return values are the same. +The first parameter is the name of the view to display. +This view is relative to your active theme's folder. +Using the helper function: echo theme_view('recent_posts'); +Using the Template method directly: -The second parameter is an optional array of data to pass to the view. This functions exactly like the second parameter of CodeIgniter's `$this->load->view()` method. Many times this won't be necessary, as any view data that is already available should be usable by any theme views also. + echo Template::themeView('recent_posts'); +The second parameter is an optional array of data to pass to the view. +This functions exactly like the second parameter of CodeIgniter's `$this->load->view()` method. +Many times this won't be necessary, as any view data that is already available should be usable by any theme views also. - echo theme_view('recent_posts', array('posts' => $posts)); - - -By default, this method will check to see if the user is viewing this from a mobile device (like a smartphone or tablet). If they are, then it will first look for a view that is prefixed with `mobile_`. + echo Template::themeView('recent_posts', array('posts' => $posts)); +By default, this method will check to see if the user is viewing this from a mobile device (like a smartphone or tablet). +If they are, then it will first look for a view that is prefixed with `mobile_`. /* - * Would look for a file called: mobile_recent_posts - * in the active theme folder. + * Would look for a file called: mobile_recent_posts in the active theme directory. */ - echo theme_view('recent_posts'); - - -If you want to ignore the mobile version (like when they have said they want to view the full site anyway) you may pass `true` in as the third parameter. + echo Template::themeView('recent_posts'); +To ignore the mobile version (for example, when a user has chosen to view the full site anyway) you may pass `true` in as the third parameter. /* - * Would look for a file called: recent_posts - * in the active theme folder, even if they - * were viewing on a mobile device. + * Would look for a file called: recent_posts in the active theme folder, and + * will not even check whether the user is viewing on a mobile device. */ - echo theme_view('recent_posts', null, true); - + echo Template::themeView('recent_posts', null, true); ### Parsing Views -Bonfire assumes that you are using PHP as your template language. However, you can still use CodeIgniter's built-in `parser` library to display your views instead of letting it parse straight PHP. This can be turned on and off with the Template library's `parse_views()` method. +Bonfire assumes that you are using PHP as your template language. +However, you can still use CodeIgniter's built-in `Parser` library to display your views instead of letting it parse straight PHP. +This can be turned on and off with the Template library's `parse_views()` method. Template::parse_views(true); - Once this command has been called, all views from this point on would use the parser. ## Themes -Bonfire supports a very flexible theme engine that allows for common layouts to wrap around your views, as well as more complex parent/child relationships between themes. Themes can include their own assets (CSS, Javascript and images), as well as multiple layout files. They can also providing layout switching based on the controller that's currently being ran. +Bonfire supports a very flexible theme engine that allows for common layouts to wrap around your views, as well as more complex parent/child relationships between themes. +Themes can include their own assets (CSS, Javascript and images), as well as multiple layout files. +They can also providing layout switching based on the controller that's currently being ran. + + +### Parent and Child Themes + +Parent/Child themes make it simple to make small tweaks to a theme without actually modifying any of the original theme's files. +Instead, you create a new theme and modify only the files that you need to change. +If a file is not found in the active theme it will use the file from the default theme in its place. + +Parent/child themes are perfect to use when you have a module that requires its own theme, like a forum, but you want to give the users the ability to choose different themes. +To create these new themes you would simply create new theme folders that only changed the layouts or assets that needed to change, while defaulting to the original theme for all other assets or layouts. + +There are two methods that you would use to setup a parent/child theme situation. + +#### set_theme($theme[, $default_theme = null]) + +The first parameter should be the name of the active (or primary) theme to use. +This is the one that will be looked into first when trying to display any themed files. +The second parameter is the name of the default (or parent) theme that is used as a fallback when themed files are not found in the active theme. +Unless otherwise specified, all themes will attempt to fall back on a theme named `default`. + + Template::set_theme('my_theme', 'default'); + +#### set_default_theme($theme) + +There may be situations where you need to only change the default theme that is used as a fallback and not change the active theme. +You would use the `set_default_theme()` method to handle this. +The only parameter is the name of the theme to use as the default. + + Template::set_default_theme('my_other_theme'); + + +### Theme Paths + +By default, all of your application's themes are stored within `public/themes`. +There may be times, though, when you need to have multiple locations to store your theme files. +This might be handy when you ship a forums module and want to provide themes specifically for your forums in their own location. + +You can add a new path to look for themes with the `add_theme_path()` method. +The only parameter is the path to your theme folder. +This must be relative to your application's web root (`FCPATH`). + + Template::add_theme_path('user_themes'); + +If you only need that path there temporarily, you can provide a slight performance increase by removing the path when you're done with it. + + Template::remove_theme_path('user_themes'); + +If you want to permanently add that path to your application, you can set this in the `application.php` config file. + + $config['template.theme_paths'] = array('user_themes', 'bonfire/themes'); -### Layouts +## Layouts -A layout is a view file that is contains common content that you want displayed on each page. This is commonly used to create consistent headers and footers across your site. +A layout is a view file that is contains common content that you want displayed on each page. +This is commonly used to create consistent headers and footers across your site. You can also have layouts for two- and three-column (or more!) formats that are ready to be used within any controller in your site. -### Default Layouts +### Default Layout -When you display a view using `Template::render()` Bonfire will use a layout called `index.php`. This is the base layout that is used across your site. +When you display a view using `Template::render()` Bonfire will use a layout called `index.php`. +This is the base layout that is used across your site. - themes/ - my_theme/ - index.php + public/ + themes/ + my_theme/ + index.php -**AJAX Calls** +#### AJAX Calls When your page is displaying a view in response to an AJAX call Bonfire will ignore the current view that has been set and instead use the `ajax.php` layout. You can use this file to fire any common javascript after an AJAX response. - themes/ - my_theme/ - ajax.php + public/ + themes/ + my_theme/ + ajax.php ### Using Arbitrary Layouts -If a page requires a different layout than the default ones, say to display a two-column layout, you can easily choose a different layout to use with the `render()` method. +If a page requires a different layout than the default, say to display a two-column layout, you can easily choose a different layout to use with the `render()` method. class Blog extends Front_Controller { @@ -180,31 +268,28 @@ If a page requires a different layout than the default ones, say to display a tw } } -You can also set a layout to be used by an entire controller by directly tapping into the Template library's class variables. +You can also set a layout to be used by an entire controller by directly tapping into the Template library's `setLayout()` method. class Blog extends Front_Controller { public function __construct() { - Template::layout = 'two_column'; + Template::setLayout('two_column'); } } -This is best used when you want this controller to use a layout that is shared with other controllers. +This is best used when you want this controller to use a layout that is shared with other controllers, or to set a default layout for a controller. ### Controller-Based Layouts If you have a controller that needs its own layout all you need to do is to create a new layout in your theme folder with the same name as your controller. - /** * Uses the blog layout file at: - * themes/ - * my_theme/ - * blog.php + * /public/themes/my_theme/blog.php */ class Blog extends Front_Controller { @@ -214,83 +299,51 @@ If you have a controller that needs its own layout all you need to do is to crea } } - -### Parent and Child Themes - -Parent/Child themes make it simple to make small tweaks to a theme without actually modifying any of the original theme's files. Instead, you create a new theme and modify only the files that you need to change. If a file is not found in the active theme it will use the file from the default theme in its place. - -Parent/child themes are perfect to use when you have a module that requires its own theme, like a forum, but you want to give the users the ability to choose different themes. To create these new themes you would simply create new theme folders that only changed the layouts or assets that needed to change, while defaulting to the original theme for all other assets or layouts. - -There are two methods that you would use to setup a parent/child theme situation. - -**set_theme()** - -The first parameter should be the name of the active (or primary) theme to use. This is the one that will be looked into first when trying to display any themed files. The second parameter is the name of the default (or parent) theme that is used as a fallback when themed files are not found in the active theme. Unless otherwise specified, all themes will attempt to fall back on a theme named `default`. - - - Template::set_theme('my_theme', 'default'); - - -**set_default_theme()** - -There may be situations where you need to only change the default theme that is used as a fallback and not change the active theme. You would use the `set_default_theme()` method to handle this. The only parameter is the name of the theme to use as the default. - - - Template::set_default_theme('my_other_theme'); - - ### Understanding Template Content In your theme's layout files, you can specify where the controller's views are set to display by using the `Template::content()` method. - - ## Blocks -Blocks allow you to set aside room for content within your layouts. It can be used as a placeholder for content that varies across layouts, like a sidebar. On a two-column layout you can set aside an area for the sidebar content, but then define what content is used there in each controller or method, allowing each page to be customized without needing additional layouts. - +Blocks allow you to set aside room for content within your layouts and views. +It can be used as a placeholder for content that varies across layouts, like a sidebar. +On a two-column layout you can set aside an area for the sidebar content, but then define what content is used there in each controller or method, allowing each page to be customized without needing additional layouts. Template::block('block_name', 'default_view'); - -The first parameter is a name that the block can be referenced by when you set the view to use in your controller. The second optional parameter is the name of a view to use as a default, in case other content has not been set. +The first parameter is a name that the block can be referenced by when you set the view to use in your controller. +The second optional parameter is the name of a view to use as a default, in case other content has not been set. If you need to pass a specific set of data to the block's view, you can pass an array of key/value pairs as the third parameter. - Template::block('block_name', 'default_view', $data); -Sometimes you will want to keep all of the various files that can be used in this block within your theme. In this case, you can pass `true` as the fourth parameter. Instead of looking within your module's view folder, it will look within the theme folder. - +Sometimes you will want to keep all of the various files that can be used in this block within your theme. +In this case, you can pass `true` as the fourth parameter. +Instead of looking within your module's view folder, it will look within the theme folder. Template::block('block_name', 'default_view', $data, true); - -To set a different view to use in that block, you would use the `Template::set_block()` method within your controller. The first parameter is the name of the block to set the content for. The second parameter is the name of the view file to use. By default, this will look within your module's view folder. - +To set a different view to use in that block, you would use the `Template::set_block()` method within your controller. +The first parameter is the name of the block to set the content for. +The second parameter is the name of the view file to use. +By default, this will look within your module's view folder. Template::set_block('sidebar', 'blog_sidebar'); - - - -## Helper Functions - -The Template library contains several other, smaller, functions and methods that change the way you might be used to using standard CodeIgniter features, as well as some to aid with building out your navigation. - -### View Data - -Instead of using a $data array to pass content to your view, or using `$this->load->vars()`, you can use `Template::set()` to make the data usable within the view. This should follow the same format that you are used to using, namely being an array of key/value pairs. +## View Data +Instead of using a $data array to pass content to your view, or using `$this->load->vars()`, you can use `Template::set()` to make the data usable within the view. +This should follow the same format that you are used to using, namely being an array of key/value pairs. // Instead of... $data = array( @@ -302,10 +355,8 @@ Instead of using a $data array to pass content to your view, or using `$this->lo Template::set('title', 'Page title'); Template::render(); - In order to make the transition from a familiar CodeIgniter practice to Bonfire simpler, you can pass an array in as the only parameter. - $data = array( 'title' => 'Page title' ); @@ -314,23 +365,25 @@ In order to make the transition from a familiar CodeIgniter practice to Bonfire Within your views, you can access the variables with a name that matches the key of the array pairs. -### Flash Messages +## Flash Messages -CodeIgniter's Session library provides flash messages that allow you to set short status messages in your views. This is commonly used for small notifications when your object saved successfully. The only limitation this has is that it only is available on a page reload, which can soon become costly due to the sheer number of server hits it creates. - -Bonfire provides a variation on this that is available both to the current page as well as the next page load. To use it you would call the `set_message()` method within your controllers. The first parameter is the text to be displayed. The second parameter is the class name that will be given to the output string. +CodeIgniter's Session library provides flash messages that allow you to set short status messages in your views. +This is commonly used for small notifications when your object saved successfully. +The only limitation this has is that it only is available on a page reload, which can soon become costly due to the sheer number of server hits it creates. +Bonfire provides a variation on this that is available both to the current page as well as the next page load. +To use it you would call the `set_message()` method within your controllers. +The first parameter is the text to be displayed. +The second parameter is the class name that will be given to the output string. Template::set_message('Your message displayed just fine.', 'success'); - To display the message, use the `message()` method within your view. + echo Template::message(); - Template::message(); - -The code is wrapped within HTML that you can define in the `application.php` config file. It defaults to a Bootstrap compatible alert message. - +The code is wrapped within HTML that you can define in the `application.php` config file. +It defaults to a Bootstrap compatible alert message. $config['template.message_template'] =<< @@ -339,72 +392,54 @@ The code is wrapped within HTML that you can define in the `application.php` con
EOD; - -### Redirect +## Redirect -When you are using AJAX a lot in your application, you will find times when CodeIgniter's stock `redirect()` method will not work for you, since it redirects within the AJAX call. What happens when you want to completely break out of the AJAX call and do a complete page refresh? You can use `Template::redirect('some/other/page')` instead. This returns an empty file that simply has a Javascript redirect code inserted. +When you are using AJAX a lot in your application, you will find times when CodeIgniter's stock `redirect()` method will not work for you, since it redirects within the AJAX call. +What happens when you want to completely break out of the AJAX call and do a complete page refresh? You can use `Template::redirect('some/other/page')` instead. +This returns an empty file that simply has a Javascript redirect code inserted. The only parameter is a URL (either absolute or relative) to redirect the user to. - Template::redirect('users/profile'); + +## Helper Functions - -### Theme Paths - -By default, all of your application's themes are stored within `bonfire/themes`. There may be times, though, when you need to have multiple locations to store your theme files. This might be handy when you ship a forums module and want to provide themes specifically for your forums in their own location. - -You can add a new path to look for themes with the `add_theme_path()` method. The only parameter is the path to your theme folder. This must be relative to your application's web root (FCPATH). - - - Template::add_theme_path('user_themes'); - -If you only need that path there temporarily, you can provide a slight performance increase by removing the path when you're done with it. - - - Template::remove_theme_path('user_themes'); - - -If you want to permanently add that path to your application, you can set this in the `application.php` config file. - - - $config['template.theme_paths'] = array('user_themes', 'bonfire/themes'); - +The Template library contains several other, smaller, functions and methods that change the way you might be used to using standard CodeIgniter features, as well as some to aid with building out your navigation. ### Working With Menus The template library contains two functions to ease working with navigation items and setting the active link within the menu. -**`check_class()`** - -The `check_class()` function checks the passed in url segments against the controller that is running. The first parameter is the name of the class to check against. If you wanted to highlight the Blog link in your main application and your controller was named 'blog' you could use: +#### `check_class($item[, $class_only = false])` +The `check_class()` function checks the passed in url segments against the controller that is running. +The first parameter is the name of the class to check against. +If you wanted to highlight the Blog link in your main application and your controller was named 'blog' you could use: >Blog // Outputs: Blog - If you already have other classes applied to the link and just want the word `active` output, you can pass `true` as the second parameter. - Blog // Outputs: Blog - -**`check_method()`** +#### `check_method($item[, $class_only = false])` Check method works the same as `check_class()` but compares it to the active method running within your controller. The parameters are identical. -**`check_segment()`** +#### `check_segment($segment_num, $item[, $class_only = false])` -Check_segment is used in much the same way as the previous two methods, but is more generic, and, often, more flexible. The first parameter is the URI segment to check. The second parameter is the value to compare the segment to. +Check_segment is used in much the same way as the previous two methods, but is more generic, and, often, more flexible. +The first parameter is the URI segment to check. +The second parameter is the value to compare the segment to. >Blog @@ -413,8 +448,7 @@ Check_segment is used in much the same way as the previous two methods, but is m If you already have other classes applied to the link and just want the word `active` output, you can pass `true` as the third parameter. - Blog // Outputs: - Blog \ No newline at end of file + Blog diff --git a/bonfire/docs/template.md b/bonfire/docs/template.md index d95c671cd..eead25fb5 100644 --- a/bonfire/docs/template.md +++ b/bonfire/docs/template.md @@ -212,6 +212,15 @@ Returns the name of the active theme. Returns the full URL to the currently active theme. If `$resource` is supplied, returns the full URL to that resource within the currently active theme (does not validate the existence of the resource within the theme). +### themeView($view[, $data = null[, $ignore_mobile = false]]) + +Set an insertion point for a view (`$view`) within a view. +- `$view`: The name of the view to be rendered. +- `$data`: An array of data to be passed to the view. +- `$ignore_mobile`: + - If `true`, the library will not attempt to find a version of this view named for mobile devices (prefixed with `mobile_`). + - If `false` (default), the library will attempt to find a version of this view named for mobile devices when it detects that the page is being accessed from a mobile device. + ### remove_theme_path($path) Remove a theme path (`$path`) from the list of paths to be used when searching for themed views. @@ -251,11 +260,7 @@ If `$item` does not match, an empty string is returned. ### theme_view($view[, $data = null[, $ignore_mobile = false]]) Set an insertion point for a view (`$view`) within a view. -- `$view`: The name of the view to be rendered. -- `$data`: An array of data to be passed to the view. -- `$ignore_mobile`: - - If `true`, the library will not attempt to find a version of this view named for mobile devices (prefixed with `mobile_`). - - If `false` (default), the library will attempt to find a version of this view named for mobile devices when it detects that the page is being accessed from a mobile device. +A helper function for `Template::themeView()`. ## Properties diff --git a/bonfire/libraries/Template.php b/bonfire/libraries/Template.php index 4ffc76781..1b44d1b01 100644 --- a/bonfire/libraries/Template.php +++ b/bonfire/libraries/Template.php @@ -8,7 +8,7 @@ * @package Bonfire * @author Bonfire Dev Team * @copyright Copyright (c) 2011 - 2015, Bonfire Dev Team - * @license http://opensource.org/licenses/MIT The MIT License + * @license http://opensource.org/licenses/MIT The MIT License * @link http://cibonfire.com * @since Version 1.0 * @filesource @@ -122,9 +122,9 @@ public static function init() } // Store our settings - self::$default_theme = self::$ci->config->item('template.default_theme'); + self::$default_theme = self::$ci->config->item('template.default_theme'); self::$layout = self::$ci->config->item('template.default_layout'); - self::$parse_views = self::$ci->config->item('template.parse_views'); + self::$parse_views = self::$ci->config->item('template.parse_views'); self::$site_path = self::$ci->config->item('template.site_path'); self::$theme_paths = self::$ci->config->item('template.theme_paths'); @@ -709,6 +709,44 @@ public static function load_view($view = null, $data = null, $override = '', $is } } + /** + * Load a view (from the current theme) and return the content of that view. + * + * Allows for simple mobile templates by checking for a filename prefixed with + * 'mobile_' when loading the view (if $ignoreMobile is false). For example, + * if $view is 'index', the mobile version would be 'mobile_index'. If the file + * is not found with the mobile prefix, it will load the regular view. + * + * @param string $view The name of the view to load. + * @param array $data An array of data to pass to the view. + * @param boolean $ignoreMobile Disable loading mobile_ prefixed views (if true). + * + * @return string The content of the loaded view. + */ + public static function themeView($view = null, $data = null, $ignoreMobile = false) + { + if (empty($view)) { + return ''; + } + + $output = ''; + + // If allowed, try to load the mobile version of the file. + if (! $ignoreMobile) { + self::$ci->load->library('user_agent'); + if (self::$ci->agent->is_mobile()) { + self::load_view("mobile_{$view}", $data, null, true, $output); + } + } + + // If output is empty, either mobile is ignored or no mobile file was found. + if (empty($output)) { + self::load_view($view, $data, null, true, $output); + } + + return $output; + } + //-------------------------------------------------------------------------- // !PRIVATE METHODS //-------------------------------------------------------------------------- @@ -717,8 +755,6 @@ public static function load_view($view = null, $data = null, $override = '', $is * Searches through the the active theme and the default theme to try to find * a view file. If found, it returns the rendered view. * - * @access private - * * @param string $view The name of the view to find. * @param array $data An array of key/value pairs to pass to the views. * @@ -845,28 +881,7 @@ protected static function debug_message($message, $force = false) */ function theme_view($view = null, $data = null, $ignore_mobile = false) { - if (empty($view)) { - return ''; - } - - $output =''; - - // If allowed, try to load the mobile version of the file. - if (! $ignore_mobile) { - $ci =& get_instance(); - - $ci->load->library('user_agent'); - if ($ci->agent->is_mobile()) { - Template::load_view("mobile_{$view}", $data, null, true, $output); - } - } - - // If output is empty, either mobile is ignored or no mobile file was found. - if (empty($output)) { - Template::load_view($view, $data, null, true, $output); - } - - return $output; + return Template::themeView($view, $data, $ignore_mobile); } /** @@ -1034,4 +1049,3 @@ function breadcrumb($my_segments = null, $wrap = false, $echo = true) return $output; } -/* End of file ./application/libraries/template.php */ From 1c87dbddea093d206df75d1c7b14b3215a93d1f0 Mon Sep 17 00:00:00 2001 From: mwhitneysdsu Date: Fri, 22 May 2015 12:09:38 -0700 Subject: [PATCH 07/11] Fix #1114 module override of default controller when default_controller is set to 'home' and both `/application/controllers/Home.php` and `/application/modules/home/controllers/Home.php` exist, visiting `http://localhost/` and `http://localhost/home` should both execute the `index()` method of `/application/modules/home/controllers/Home.php`. --- bonfire/core/BF_Router.php | 36 ++++++++++++++++++++++++++++++++++++ bonfire/docs/changelog.md | 1 + bonfire/docs/upgrade/074.md | 5 ++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/bonfire/core/BF_Router.php b/bonfire/core/BF_Router.php index 1b5af5e68..937136d03 100644 --- a/bonfire/core/BF_Router.php +++ b/bonfire/core/BF_Router.php @@ -69,6 +69,20 @@ class BF_Router extends CI_Router private $located = 0; + /** + * Class constructor runs the route mapping function in CI3. + * + * @param array $routing Optional configuration values. + * + * @return void + */ + public function __construct($routing = null) + { + parent::__construct($routing); + + log_message('info', 'BF_Router class initialized'); + } + /** * Get the name of the current module. * @@ -227,6 +241,28 @@ public function locate($segments) $this->located = -1; } + /** + * Set the default controller. + * + * NOTE: this method should be protected for use with CI3, but must be public + * for use with CI2. + * + * @return void + */ + public function _set_default_controller() + { + if (empty($this->directory)) { + // Set the default controller module path. + $this->_set_module_path($this->default_controller); + } + + parent::_set_default_controller(); + + if (empty($this->class)) { + $this->_set_404override_controller(); + } + } + /** * Set module path. * diff --git a/bonfire/docs/changelog.md b/bonfire/docs/changelog.md index 5a1842253..7bd3a4cef 100644 --- a/bonfire/docs/changelog.md +++ b/bonfire/docs/changelog.md @@ -7,6 +7,7 @@ #### New Features: #### Closes Issues: +* #1114 Differences in Routing between CI2 and CI3 * #1113 Syntax error in the builder-built view (when adding a required input field) * #1112 Can't login to site when offline in CI3 diff --git a/bonfire/docs/upgrade/074.md b/bonfire/docs/upgrade/074.md index 9d2c9f107..b06936584 100644 --- a/bonfire/docs/upgrade/074.md +++ b/bonfire/docs/upgrade/074.md @@ -3,4 +3,7 @@ ## 0.7.3 to 0.7.4 1. Update `/application/hooks/App_hooks.php`. -2. Update `/bonfire/modules/builder/`. +2. Update `/bonfire/core/BF_Router.php`. +3. Update `/bonfire/docs/`. +4. Update `/bonfire/libraries/Template.php`. +5. Update `/bonfire/modules/builder/`. From ee216508de647335c771c0bf157ea3d2893d21ef Mon Sep 17 00:00:00 2001 From: mwhitneysdsu Date: Thu, 28 May 2015 07:08:40 -0700 Subject: [PATCH 08/11] Fix #1115 Settings_lib->update_batch() attempts to insert without 'module' --- bonfire/docs/changelog.md | 1 + bonfire/docs/upgrade/074.md | 1 + bonfire/modules/settings/libraries/Settings_lib.php | 3 +++ 3 files changed, 5 insertions(+) diff --git a/bonfire/docs/changelog.md b/bonfire/docs/changelog.md index 7bd3a4cef..de142ef19 100644 --- a/bonfire/docs/changelog.md +++ b/bonfire/docs/changelog.md @@ -7,6 +7,7 @@ #### New Features: #### Closes Issues: +* #1115 Can't save settings, 'module' field not being sent to settings table * #1114 Differences in Routing between CI2 and CI3 * #1113 Syntax error in the builder-built view (when adding a required input field) * #1112 Can't login to site when offline in CI3 diff --git a/bonfire/docs/upgrade/074.md b/bonfire/docs/upgrade/074.md index b06936584..da57999aa 100644 --- a/bonfire/docs/upgrade/074.md +++ b/bonfire/docs/upgrade/074.md @@ -7,3 +7,4 @@ 3. Update `/bonfire/docs/`. 4. Update `/bonfire/libraries/Template.php`. 5. Update `/bonfire/modules/builder/`. +6. Update `/bonfire/modules/settings/libraries/Settings_lib.php`. diff --git a/bonfire/modules/settings/libraries/Settings_lib.php b/bonfire/modules/settings/libraries/Settings_lib.php index 4a3b40fce..9d2124bc8 100644 --- a/bonfire/modules/settings/libraries/Settings_lib.php +++ b/bonfire/modules/settings/libraries/Settings_lib.php @@ -366,6 +366,9 @@ public static function update_batch($data) if (isset($internalCache[$record[$index]])) { $updateData[] = $record; } else { + if (! isset($record['module'])) { + $record['module'] = 'core'; + } $insertData[] = $record; } self::$cache[$record[$index]] = $record['value']; From b189c2e6fe17be92757c7a7e3de92c41c1cc4ba4 Mon Sep 17 00:00:00 2001 From: mwhitneysdsu Date: Thu, 4 Jun 2015 06:24:04 -0700 Subject: [PATCH 09/11] Attempted fix for #1116, #1113 --- bonfire/docs/changelog.md | 1 + bonfire/modules/builder/views/files/view_default.php | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bonfire/docs/changelog.md b/bonfire/docs/changelog.md index de142ef19..311016500 100644 --- a/bonfire/docs/changelog.md +++ b/bonfire/docs/changelog.md @@ -7,6 +7,7 @@ #### New Features: #### Closes Issues: +* #1116 Syntax error in the builder-built view (when adding a required input field), pt 2. * #1115 Can't save settings, 'module' field not being sent to settings table * #1114 Differences in Routing between CI2 and CI3 * #1113 Syntax error in the builder-built view (when adding a required input field) diff --git a/bonfire/modules/builder/views/files/view_default.php b/bonfire/modules/builder/views/files/view_default.php index 1c1ad0723..e4477308f 100644 --- a/bonfire/modules/builder/views/files/view_default.php +++ b/bonfire/modules/builder/views/files/view_default.php @@ -29,7 +29,7 @@ if (is_array($validation_rules)) { foreach ($validation_rules as $key => $value) { if ($value == 'required') { - $required = ". lang('bf_form_label_required')"; + $required = " . lang('bf_form_label_required')"; $required_attribute = true; } } @@ -40,7 +40,7 @@ case 'textarea': $viewFields .= PHP_EOL . "
\"> - 'control-label')); ?> + 'control-label')); ?>
'{$form_name}', 'id' => '{$form_name}', 'rows' => '5', 'cols' => '80', 'value' => set_value('$form_name', isset(\${$module_name_lower}->{$field_name}) ? \${$module_name_lower}->{$field_name} : '')" . ($required_attribute ? ", 'required' => 'required'" : "") . ")); ?> @@ -50,7 +50,7 @@ case 'radio': $viewFields .= PHP_EOL . "
\"> - 'control-label', 'id' => '{$form_name}_label')); ?> + 'control-label', 'id' => '{$form_name}_label')); ?>