Yii: add custom attributes to CheckBoxes genrated with CHhtml::checkBoxList
Edit the CHtml.php file (or even better to extend the class), checkBoxList function and replace the loop with the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | /** * ZU: modified to include custome attributes for each checkbox item via the htmlOptions =>options property. * Works the same as in dropDownList control. */ foreach($data as $value=>$label) { //make copy of the original $htmlOptions array $optionsCopy = array_merge($htmlOptions); ///unset the option property from the copy so that it doesn't cause errors in other functions attempting to process the array unset ($optionsCopy['options']); $checked=!is_array($select) && !strcmp($value,$select) || is_array($select) && in_array($value,$select); $checkAll=$checkAll && $checked; $optionsCopy['value']=$value; $optionsCopy['id']=$baseID.'_'.$id++; ///if there are any custom attributes set for this checkbox, set them on the copied array if ( isset ($htmlOptions['options'], $htmlOptions['options'][ $optionsCopy['value'] ]) ) { $custAttrs = $htmlOptions['options'][ $optionsCopy['value'] ]; foreach ($custAttrs as $attrKey => $attrVal) { $optionsCopy[$attrKey] = $attrVal; } } $option=self::checkBox($name,$checked,$optionsCopy); $label=self::label($label,$optionsCopy['id'],$labelOptions); $items[]=strtr($template,array('{input}'=>$option,'{label}'=>$label)); } unset ($htmlOptions['options'] ); |
Installing PEAR and PHPUnit on Windows
Having run into trouble after trying to install PEAR by following the PEAR installation guide, I had to do the following to get it all working.
First issue was that the command go-pear.bat came up with an error saying it could not locate the PEAR\go-pear.phar file, even though the file existed in that location. The solution was to execute the file via file explorer (not within a command prompt). For some reason this worked and installed PEAR.
Then to add the various paths to the environment variables, I ran the generated registry file.
Next I proceeded to install PHPUint by following the guide. It soon produced an error informing me that the installed version of PEAR was too old! You might wonder why doesn’t PEAR install the lateste version at the time of install? I have no idea – if you do, then please enlighten me!
So to upgrade PEAR, you need to issue the following command: pear upgrade
Armed with the latest version, I continued with PHPUnit install…only to find out that the installer was having trouble with the install path. My php install is in c:\program files\php. Therefore, this is where I was running all my commands from. The installer was apparently having trouble with “program files” folder and was trying to find “program” folder, which generated the error. This was obviously caused by the space character in the folder name.
To get around this, I had to go back and edit all the path names in the PEAR generated registry file to use the old DOS style 8 character folder name – progra~1 (instead of ‘program files’).
After updating all the env. variable and re-running the PHPUnit install, everything worked perfectly without any further issues.
Hope this helps someone to save some time!
E4X Tip: Array of attribute values with one line of code
Task – to get a list of node IDs from an XML doc without using a for loop
Given the following bit of XML -
<item id="15" />
<item id="16" />
<item id="17" />
<item id="18" />
<item id="19" />
<item id="20" />
var list:Array = [];
xmlData.item.( list.push( @id ) );
trace( list ) // 15, 16, 17, 18, 19, 20
It’s simple as that – no loops, nothing!
Leave a comment if you found this useful.
E4X – Updating multiple node values
Something that is often required when processing XML documents is to update a bunch of nodes that are spread throughout the document.
Consider the following XML:
<gallery base="images/projects/"> <project id="1" > <item type="image" thumb="image1.jpg"> <path>l_image1.jpg</path> </item> </project> <project id="2"> <item type="image" thumb="image2.jpg"> <path>l_image2.jpg</path> </item> </project> <project id="3"> <item type="image" thumb="image1.jpg"> <path>l_image1.jpg</path> </item> <item type="image" thumb="image3.jpg"> <path>l_image3.jpg</path> </item> <item type="image" thumb="image4.jpg"> <path>l_image4.jpg</path> </item> <item type="image" thumb="image5.jpg"> <path>l_image5.jpg</path> </item> </project> </gallery>
Lets assume that we need to load the thumbnails of each item specified by the thumb attribute. I often use a base path for the images. It make a lot of sense to include it at document level rather than repeating it in each property value. Doing so reduces file size and also makes path updates quick and painless.
Once the XML document is loaded, the thumb path can be updated with a single line of code:
galleryXML..item.(@thumb = baseUrl + @thumb);
where baseUrl variable holds the base path. Or we can directly substitute with the value of base property like so:
galleryXML..item.(@thumb = galleryXML.@base.toString() + @thumb);
A trace of galleryXML will show that the path of each thumb attribute is prefixed with the base path.
Installing Apache + MySQL + PHP on Windows 7 64Bit
The process is pretty straight-forward, except for a few bumps along the way. The majority of problems were caused by the Access Control functionality of Win 7. Make sure your text editor is running with admin rights. Without which you’ll not be able to save any edits to the config files.
The first issue was during Apache (2.2.14-x86) install; kept getting the following error:
Errors reported here must be corrected before the service can be started. httpd.exe: Could not reliably determine the server's fully qualified domain name , using 192.168.1.3 for ServerName (OS 10048) Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down Unable to open logs Note the errors or messages above, and press the key to exit. 24...
After 10mins of trying to figure out the problem with no success, did a search and found that this was due to port 80 being used by another program – typically Skype! Which made sense as I had Skype running. Once I quit Skype and restarted Apache, everything started up smoothly.
Next, I wanted to get my virtual hosts setup. I like to keep my virtuals in their own separate file – 1 file per host. This is pretty easy to set up – just direct Apache to load up additional conf files with an “Include” directive.
NOTE: There’s a sample virtual host config file included with the Apache install in “conf/extra” folder, which may be modified to your needs.
Open the default httpd.conf and add the following to the end of it.
# Setup virtual hosts # Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost DocumentRoot "D:/webapps/_root"
<Directory /> Order Allow,Deny Allow from all </Directory>
</VirtualHost>
Include "D:/webapps/_virtuals/*.conf"
Next, create blog.conf file with the following content. Make sure to give it a meaningful name – something like blog.sprit3.conf, so that it can be located easily. Save the file in the _virtuals folder.
<VirtualHost *:80>
ServerName blog.sprit3.net DocumentRoot "D:/webapps/www/blog.sprit3"
<Directory /> Order Allow,Deny Allow from all </Directory>
</VirtualHost>
By default Apache will deny any requests to the virtual folders unless allowed explicitly. Hence the <Directory> tag.
Save this in the _virtuals folder and restart Apache. Verify if virtuals are running properly by entering “httpd -S” via the command prompt.
Next step is to add the virtual host address to the local host file so that any requests to blog.sprit3.net will be directed to my localhost instead of the live site. Windows hosts file is located at %SystemRoot%/system32/drivers/etc folder.
That should get the virtual folder running and all the web apps nicely organised!
