Recent Posts

Tuesday, August 23, 2011

Cake PHP losing session in Google Chrome

I was having problem where i was losing my sessions and when i logged in as admin after every click i would have to login again.
After few searches i found out below article on pixelastic that was pretty helpful...

It might help you guys


Read more!

Tuesday, August 9, 2011

Avoid Undefined Index in CakePHP

There might be various problems regarding to undefined index in CakePHP and there are many solutions to it and some links i went through to fix the problem are:

Newby: "Undefined index" error
Something on CakePHP Notice (8): Undefined Index
CakePHP: Rendering an undefined index

However these couldn't help solve my problem, being newbie in Cake and after going through these posts, it clicked me that i might be doing something silly mistake.

Actually i was displaying news in my default page where I declared the variable news in apps_controller as below:

function beforeRender(){
$todayNews = $this->News->find('first', array( 'order' => array( 'News.updated' => 'DESC' ) ) );

$this-> set('news', $todayNews);


And in my news controller I was using below code to render my index page:

function admin_index()
$allNews = $this->News->find('all',
'order' => array
( 'News.updated' => 'DESC' ) )

$this -> set('news',$allNews);

You can see both had "news" being set. So when i called my index page i was always getting

Notice (8): Undefined index: News [APP\views\news\admin_index.ctp, line 18]

This made me go round and round for an hour... finally found out ti was the same variable causing problem.

then I changed the variable in my app_controller to be

function beforeRender(){
$todayNews = $this->News->find('first', array( 'order' => array( 'News.updated' => 'DESC' ) ) );

$this-> set('displaynews', $todayNews);

and called the same in my default layout page and all worked like a charm... hope this will help save you some time that might use creatively..... Enjoy coding.

Read more!

Tuesday, July 12, 2011

Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on (Multi-Threaded Applicaiton)

I was stuck on this for hours where the event raised from the class wouldn' t write to my textbox in the presentation layer.

I googled but could not find any concrete solution to this but at last after going through various websites i figured out the easier way to solve this.

This article will help users to call the function in the class and raise an event within the class and catch the event in form and display whatever message raised to the text boxes in multi threaded application (
Lets go step by step now:

1. I have a form with command button cmdTest and text box txtAction where I display my messages raised from the class.

Private Sub cmdTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTest.Click
Dim robot As New RobotProcess_Ama(Nothing)
AddHandler robot.TaskProcessed, AddressOf ActionLog
WorkerThread = New Threading.Thread(AddressOf robot.CheckQueue)
End Sub

Private Sub ActionLog(ByVal FunctName As String, ByVal aMessage As String)
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
txtAction.Text = TimeString & "From: " & FunctName & ":" & aMessage
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = True
End Sub

Here i disabled checkforIllegalcrossThreadcalls and re-enabled them after finishing.

2. Now my class RobotProcess_Ama contains function called checkqueue and raises the message.
Public Sub CheckQueue()
RaiseEvent TaskProcessed("From Class", TimeString & ": Creating log file")
' Threading.Thread.Sleep(200)

Catch ex As Exception
Throw ex
End Try
End Sub

Read more!

Wednesday, June 29, 2011

CakePHP: Auto populating foreign key dropdown fields

I wasted so much time figuring out to populate the drop down from foreign classes in cake PHP and wished it would be best if someone could have written from beginning to end to help the beginners of Cake like me.

Finally i figured it out and you guys can benefit from it.

I have two tables articles and users, user write articles so there is one to many relationship. I need user drop down in articles forms to say who is this user writing the article.

User table has

Article table has

So my Article Model will look like below:

My user model will look like below:

My Article Controller will look like below

The Add view will look like below:

Similarly Edit View will look like below

Hope this will help kick start your Cake Php learning ... enjoy coding

Read more!

Wednesday, June 22, 2011

OO database connection class in PHP

I got good OO database connectivity class for PHP tutorial in the following site:

Enjoy guys

Read more!

Wednesday, June 15, 2011

Blogger Tips And Tricks|Latest Tips For Bloggers: How To Add Google +1(plus) Button With Blogger Sha...

Blogger Tips And Tricks|Latest Tips For Bloggers: How To Add Google +1(plus) Button With Blogger Sha...: "This quick and easy tutorial will explain how to enable Google +1 Button with Blogger Share Buttons. If you are already using Blogger share ..."

Read more!

Wednesday, May 18, 2011

Disable close button in form without losing icon on the form

In a module write the following code:

'for close button declaration
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
Private Const MF_DISABLED = &H2

Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As IntPtr, ByVal nPosition As Integer, ByVal wFlags As Long) As IntPtr
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As IntPtr, ByVal bRevert As Boolean) As IntPtr
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As IntPtr) As Integer
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As IntPtr) As Boolean

Public Sub DisableCloseButton(ByVal hwnd As IntPtr)
Dim hMenu As IntPtr
Dim menuItemCount As Integer

hMenu = GetSystemMenu(hwnd, False)
menuItemCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, menuItemCount - 1, MF_DISABLED Or MF_BYPOSITION)
Call RemoveMenu(hMenu, menuItemCount - 2, MF_DISABLED Or MF_BYPOSITION)
Call DrawMenuBar(hwnd)
End Sub

Then in the form.load() where you want to disable the close button just call function as below:


Read more!

Sunday, January 23, 2011

How to remove xmlns namespace from xml using

I was having issues with xmlns in xml file and was creating unnecessary waste of time handling them. But i found below solution to remove xmlns from the xml file so that I can focus on only the required tags.

Function stripDocumentNamespace(oldDom As XmlDocument) As XmlDocument
' Remove all xmlns:* instances from the passed XmlDocument
' to simplify our xpath expressions.
Dim newDom As New XmlDocument()
newDom.LoadXml(System.Text.RegularExpressions.Regex.Replace(oldDom.OuterXml, "(xmlns:?[^=]*=[""][^""]*[""])", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase Or System.Text.RegularExpressions.RegexOptions.Multiline))
Return newDom
End Function

Read more!