Yearly Archives: 2014

Convert Yii Boilerplate to Boostrap 3

Rather than keep this in my post Building an application with Yii , I decided this warranted a post of it’s own since it was quite specific. As a developer of course I want to use the new shiny and not Bootstrap v2.3.2 that Yii Boilerplate came with. It wasn’t as easy as updating the version in my composer.json file since all the classes for Yii-Booster changed from something like “BoostrapNavbar” to BoosterNavbar” . So, in all it’s glory, are the changes from my git commit. Note there were additional changes to composer.json and composer.lock that I did not include here… the only relevant change was bumping the version to “clevertech/yii-booster”: 4.0.1″ . Basically we’re changing references to “bootstrap” to “booster”. Some CSS was also added in main.css to make the navbar look the same since Bootstrap v3 is mobile first.

@media (min-width: 768px) {
	.nav li{display:inline-block;}
backend/components/BackendController.php |    2 +-
 backend/config/overrides/base.php        |    6 +-
 backend/views/layouts/_navigation.php    |    4 +-
 backend/views/layouts/main.php           |    2 +-
 backend/views/site/login.php             |    6 +-
 backend/www/index.php                    |    2 +-
 composer.json                            |    4 +-
 composer.lock                            | 2652 ++----------------------------
 8 files changed, 184 insertions(+), 2494 deletions(-)

diff --git a/backend/components/BackendController.php b/backend/components/BackendController.php
index a2c8c68..05c5b59 100644
--- a/backend/components/BackendController.php
+++ b/backend/components/BackendController.php
@@ -31,7 +31,7 @@ abstract class BackendController extends CController
         return array(
-            array('bootstrap.filters.BootstrapFilter - delete'),
+            array('booster.filters.BoosterFilter - delete'),
diff --git a/backend/config/overrides/base.php b/backend/config/overrides/base.php
index b068422..9d5c9ba 100644
--- a/backend/config/overrides/base.php
+++ b/backend/config/overrides/base.php
@@ -16,9 +16,9 @@ return [
     'components' => [
         // Backend uses the YiiBooster package for its UI
-        'bootstrap' => [
-            // `bootstrap` path alias was defined in global init script
-            'class' => 'bootstrap.components.Bootstrap'
+        'booster' => [
+            // `booster` path alias was defined in global init script
+            'class' => 'booster.components.Booster'
         'errorHandler' => array(
             // Installing our own error page.
diff --git a/backend/views/layouts/_navigation.php b/backend/views/layouts/_navigation.php
index c122336..aaaf8a9 100644
--- a/backend/views/layouts/_navigation.php
+++ b/backend/views/layouts/_navigation.php
@@ -6,7 +6,7 @@
-    'bootstrap.widgets.TbNavbar',
+    'booster.widgets.TbNavbar',
         'type' => 'inverse',
         'brand' => 'Project name',
@@ -14,7 +14,7 @@ $this->widget(
         'collapse' => true,
         'items' => array(
-                'class' => 'bootstrap.widgets.TbMenu',
+                'class' => 'booster.widgets.TbMenu',
                 'items' => array(
                     array('label' => 'Home', 'url' => array('/site/index')),
diff --git a/backend/views/layouts/main.php b/backend/views/layouts/main.php
index 4d097c9..35a2ba1 100644
--- a/backend/views/layouts/main.php
+++ b/backend/views/layouts/main.php
@@ -28,7 +28,7 @@
breadcrumbs)): ?> widget( - 'bootstrap.widgets.TbBreadcrumbs', + 'booster.widgets.TbBreadcrumbs', array( 'links' => $this->breadcrumbs, ) diff --git a/backend/views/site/login.php b/backend/views/site/login.php index 91e20b2..12158b9 100644 --- a/backend/views/site/login.php +++ b/backend/views/site/login.php @@ -16,7 +16,7 @@ $this->breadcrumbs = ['Login']; beginWidget( - 'bootstrap.widgets.TbActiveForm', + 'booster.widgets.TbActiveForm', array( 'id' => 'login-form', 'enableClientValidation' => true, @@ -42,8 +42,8 @@ echo CHtml::errorSummary($model, null, null, array('class' => 'alert alert-error
- widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit','type'=>'primary','label'=>'Submit', 'icon'=>'ok'));?> - widget('bootstrap.widgets.TbButton', array('buttonType'=>'reset','label'=>'Reset'));?> + widget('booster.widgets.TbButton', array('buttonType'=>'submit','type'=>'primary','label'=>'Submit', 'icon'=>'ok'));?> + widget('booster.widgets.TbButton', array('buttonType'=>'reset','label'=>'Reset'));?>
endWidget(); ?> diff --git a/backend/www/index.php b/backend/www/index.php index 50636eb..bef5f00 100644 --- a/backend/www/index.php +++ b/backend/www/index.php @@ -15,7 +15,7 @@ Yii::setPathOfAlias('www', ROOT_DIR . '/backend/www'); # As we are using BootstrapFilter to include Booster, we have to define 'bootstrap' alias ourselves # Note that we are binding to Composer-installed version of YiiBooster -Yii::setPathOfAlias('bootstrap', ROOT_DIR . '/vendor/clevertech/yii-booster/src'); +Yii::setPathOfAlias('booster', ROOT_DIR . '/vendor/clevertech/yii-booster/src');

Building an application with Yii 1

I’ve built a couple projects with Yii previously and really enjoyed how easy it was to rapidly build a professional application. For my new Yii project I have a set of user requirements and about 100 hours to get it done. So, I’m going to look into some Yii extensions and packages to build this out even more rapidly than before. From a development standpoint, I have just a few requirements:

  1. Yii v1.x
  2. Boostrap CSS v3
  3. Separated front and backend
  4. User and role management


What is Yii Phundament?

I tried out this Yii package and after asking this question for about an hour and a half, I decided it wasn’t suited for my project. There isn’t any decent documentation explaining what Phundament is, other than “you will like it”. I might have liked it if there was a little documentation. Unfortunately it’s not worth any more of my time to try and figure out what it is and how to use it. It’s basically Yii with about 20 extensions, most of which I probably wouldn’t need, that are installed via composer. It appears to be a CMS application on top of Yii. Here is a link to the phundament demo.


Yii Boilerplate

For my project I ended up going with Yii Boilerplate primarily because it already has the backend and frontend separated, along with environment overrides, already thought out and implemented. Here is an installation tutorial that is mostly correct, but there were a few instructions that were no longer correct, like the names of the override files. The instructions also didn’t mention where to run yiic from, which is the /bin directory. There are a number of development tools required by composer, such as selenium and Symphony components that I won’t be using out of the box, but I’ll leave them for now and may use them later. I had this installed and was able to log into the backend and the Gii module in about 20 minutes.


Boilerplate tweaks

  1. I wanted to use Bootstrap CSS v3, and the composer package “clevertech/yii-booster”: “dev-master” that comes with boilerplate will give you Boostrap v2. Once you run “composer update”, the “dev-master” will give you the latest version of yii-booster, which will cause errors such as “Alias “bootstrap.filters.BootstrapFilter” is invalid” . So, you’ll need to change the composer.json file to “clevertech/yii-booster”: “3.1.1” . Or, if you want to use bootstrap 3 like I did, then follow these instructions to make Yii Boilerplate use bootstrap 3

Magento bundle error “Please select options for product” or “Please specify product option(s)” 1

I had a need to turn a simple product in to a bundled product b/c our client wanted to make an add on service available for purchase with it. Of course there isn’t a way to change the product type after it’s been created (there are plugins but at this time one is not available to turn a simple product into a bundle (there is one but you can’t download it)).

I created a new product as a bundle product and copied over all the info from the original, and had the intention of deleting the original simple product. So, the new bundled product was configured with a price and had one non required bundled option, which is the add on service product. Upon adding this to the cart, I kept getting the error “Please select options for product” or “Please specify product option(s)” . Also, the “as low as” price for the bundled product was wrong, but it’s lowest price included the price of the non required option. This is because I setup the bundle incorrectly. The correct way to configure this is to create a new product for the bundled as I did, but set it’s price to zero, and add the original simple product along with the add on service as bundle options. The original product would be required and had a price, while the add on service would be optional. Also, I made the original simple product not visible individually, so the only way to find it would be via the new bundled product.

After 20 min or so of searching, Norberto Burciaga’s article described the problem and solution perfectly.

RetroPie emulationstation not saving game progress 3

I spent part of my Saturday on this issue where I’d make progress in a game and save it within the game, but upon powering down the raspberry pi and returning, the progress would be gone. The problem is if you’re not exiting the game “cleanly”, the the emulation station will not write the game progress to the SD card, even though you’ve saved it in the game. When you configure a controller with RetroPie, it does not present you with a button combination to exit the game, which will initiate a write to the SD card. You can manually add a button combination for your controller by logging into the terminal and going to /opt/retropie/emulators/RetroArch/configs/ , then selecting your controller config, and adding the below two lines:

input_enable_hotkey_btn = 8
input_exit_emulator_btn = 9

Within the config, you’ll see each button on your controller is assigned a number. On my NES controller the “select” button was 8 and the “start” button was 9. With these lines added to the config file, I now press select and start at the same time to exit the game cleanly (which saves progress to the SD card).

Also, you can configure an automatic write to the SD card at an interval. Edit your retroarch.cfg file and uncomment the line “autosave_interval” and set it’s value to an integer representing a number of seconds. For example

autosave_interval = 5

Will save your progress to the SD card every 5 seconds.

Magento get options name and value for specific attribute

$attributeName = 'your_attribute_name';
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product',$attributeName);
	foreach($attribute->getSource()->getAllOptions(true,true) as $option){
		$o .= '<li><a href="' . $option['value'] . '">' . $option['label'] . '</a></li>';