Laravel 4.2 Controller Subfolder routing

This is a simple way to organize your controller files or create sub folder under the controller folder.

1

After you created the folder, controllers and setup your routing. Then you need to run this into your command prompt.
otherwise you’ll encounter  this error message.

ErrorException (E_WARNING). failed to open stream: No such file or directory

Run this script

artisan dump-autoload

artisan

 

 

Jquery – SerializeArray()

jQuery SerializeArray() sample code how to send request to your server.

 $.ajax({
    type: "POST",
    url: $(this).attr('action'),
    dataType: "json",
     data     : $(this).serializeArray(),
     success: function(data) {
        if (data.status) { 
		// Success this should redirect or refresh the page. 
		//document.location.reload(true); 
        } else {
		// Error Message 
        }
    },
    error: function(){
              // Error Message 
    }
});

CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource

Here are some issue we encountered when we are using custom font “woff or ttf”.

error-font

Simply go to your .htaccess and add this line.

<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css)$">
    Header set Access-Control-Allow-Origin "*"
  </FilesMatch>
</IfModule>

And make sure when you are saving your .htaccess it has the permission and tried to open and reopen it again just to make sure the the code is added.

jQuery error Access-Control-Allow-Origin when sending post request

We encountered weird error when we are requesting to another domain. Actually it is the same domain but on a sub domain.

Here was the error I encountered

error-oregano
I went to my .htaccess and I add this line of code.

Header add Access-Control-Allow-Origin http://www.domain.com

This will specify the domain you want to allow for security purposes and solve my issue.

Moving Image from current directory to another using Laravel 3.2

I have one task that will move the product images to one folder.
I have create and validate it using Laravel 2.2 Framework.This will get all the product images validate if the picture existed to the directory if not then display the no.png image otherwise copy the file and move it to the new directory.

$rsProduct = Products::get_ProductByCategoryId2($categoryList->id); // I am getting the records set of the products

$pathFolder = path('public').'menu/'.Products::urlReplaceDefault($categoryList->category_name);

if (!file_exists($pathFolder))
{
mkdir($pathFolder, 0777);
}

echo $categoryList->category_name;

foreach($rsProduct as $item)
{

$urlPath = path('public'). "/path/to/pictures/thumb/".$item->pic;

$newFilename = "";
if (!file_exists( $urlPath ) )
{
$urlPath = path('public'). "/path/to/pictures/thumb/no.png";
$newFilename = Products::urlReplaceDefault($item->title).".png";
}
else
{
if ($item->pic!="")
{
$newFilename = explode('.', $item->pic);
$extension = $newFilename[1];

$newFilename = Products::urlReplaceDefault($item->title);
$newFilename = $newFilename . "." . $extension;

}
else
{
$urlPath = path('public'). "/path/to/pictures/thumb/no.png";
$newFilename = Products::urlReplaceDefault($item->title).".png";
}
}

copy($urlPath, $pathFolder."/".$newFilename);

}

 

How to update value form plist using Objective-C

I have this challenge when I was doing a ios mobile application. My issue was to update an value of the plist from 0 to 1. 🙂 Sometimes it hard to find in the web with this kind of issue, very simple problem but lots of people can’t find in the web and for those people who are like me just starting to build more mobile application.

Here is the sample code.

Here is the sample plist what am talking about.

Screen Shot 2016-03-16 at 11.00.33 PM

Here is the code. I am assume that you already know how to get your record from the plist. How this works is when I press the button inside the UITableView it calls out the IProcess. The event capture the button possition of the button and get the indexPath selected.

- (IBAction)IProcess:(UIButton *)sender
{
    CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:dTableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
    
    // I will be getting the data from my mutable array data
    // with the selectedIndedPath from my uiTableView
    
    NSArray *copySelectedSection = [data objectAtIndex:indexPath.section];

    // Initialize my Value Fom the Plist
    NSMutableDictionary *ValueFromThePlist = [[NSMutableDictionary alloc] init];

    [ValueFromThePlist addEntriesFromDictionary:(NSDictionary *)copySelectedSection];
    
    // Get the value form the data
    NSNumber *isStatus = (NSNumber *)[ValueFromThePlist objectForKey:@"status"];
    
    // Create if statement to verify if the value of the status is 1 then if true set to 0
    if ([isStatus isEqualToNumber:[NSNumber numberWithInt:1]])
    {
        [ValueFromThePlist setObject:[NSNumber numberWithInt:0] forKey:@"status"];
    }
    
    // now since you have updated the value from the record you need to loop again the data from the plist and ammed the value you have selected.
    //

    int ctr = 0;
    NSNumber *indexNumberRow =  [NSNumber numberWithInt:(long)indexPath.row];
    NSMutableArray *newSetOfarray = [NSMutableArray arrayWithCapacity:0];
    for (NSDictionary *mainSection in copySelectedSection) {
        
        if ([indexNumberRow isEqualToNumber:[NSNumber numberWithInt:ctr]])
            
        {
            [newSetOfarray addObject:(NSArray*)ValueFromThePlist];
        }
        else{
            [newSetOfarray addObject:(NSArray*)mainSection];
        }
        
        ctr++;
        
        //
    }
    
    NSString *filePath = [self getDatabasePath];
    
    NSError *error;
    
    NSData *plistData = [NSPropertyListSerialization dataWithPropertyList:(NSDictionary *)newSetOfarray format:NSPropertyListXMLFormat_v1_0 options:NSPropertyListImmutable error:&error];
    
    if(plistData)
    {
        [plistData writeToFile:filePath atomically:YES];
    }
    // DONE DONE DONE 
}

I hope this will help you as well to fix or to solve some simple things just like what I encountered. Happy Coding!!!

How to resolve 421 Too many connections (8) from this IP

I’ve been knocking my head and waiting for a very longest time for my turn to upload my files to server (because of my colleague is uploading large files to the server).  While waiting to that, I was murmuring so hard, I spelling out maybe she can upload using cPanel while waiting for couple of minutes or hours. On the otherside, Maybe I can do as well. Atleast I can do my job done.

anyways.. Here is a instruction how to resolve your issue with your filezilla connection issue.

1. Go to File
2. Choose Site Manager
3. Select Transfer Setting tab
4. Check/Tick the “Limit number of simultaneous connections”
5. Set the “Maximum number of connections” to 1

filezila

Sometimes  if you did the settings and still encounter the same issue. I suggest to restart your router so that it will completely shut off all the connection.

Alternative solution to fix the error 421, If you have an access to you cPanel account.

Go to you cPanel Account
ftp

Then you can eliminate any ftp connection connected.

session

Laravel 4.2 Login Auth via jQuery Ajax

My colleague design the login that pops up.

Here is my Javascript

// JavaScript Document Tabs 01
$(document).ready(function() {
	$('#formPopupLogin').submit(function(){
		 $.ajax({
	        type: "POST",
	        url: $(this).attr('action'),
	        dataType: "json",
	         data     : $(this).serializeArray(),
	         success: function(data) {
	            if (data.status) { 
// Success this should redirect or refresh the page. 
document.location.reload(true);
				} 
	            else {
				$('.errorWithLogin').html(data.errorMessage);
				$('.errorWithLogin').removeClass('hide');
	            }
	        },
	        error: function()
	        {
	            $('.errorWithLogin').html(server_error_message);
				$('.errorWithLogin').removeClass('hide');
	        }
	    });

		return false;
	});

});

and here is my controller function

public static function authLogin()
	{
		$input = Input::all();

		// Entry Record 
		$dataRecord = array('Username'=>$input['txtUsername'],
					'Password'=>$input['txtPassword']);

		// For my Future used
		$session_id  = Session::getId();

		// Validation
		$validator = Validator::make($dataRecord, User::$rulesLogin);

		// Intialize Arayy 
		$data = array();
		$data['status'] = 0; // Reload the page success 
		
		if ($validator->fails())
		{
			$htmlContent = "";
			$errors = $validator->errors()->getMessages();

			foreach ($dataRecord as $key => $value) {
				 $htmlContent .= "<p>".$errors[$key][0]."</p>"; /// I checked the result it is always zero // Then I assume that this display only zero // Lazy me. 
			}
			
			$data['errorMessage'] =  $htmlContent;
		}
		else 
		{	
			$rememberMe = false;	
			// Design doesn't capture remember me. 
			// So I remove it. 
			// if (isset($input['remember']))
			// {
			// 	$rememberMe = true;
			// }
			
			// validate the credentials 

			if (Auth::attempt(array('username' => $input['txtUsername'], 
									'password' => $input['txtPassword'], 
									'status'=>'1'), $rememberMe))
			{	
					
					if (Auth::check())
					{
						
					}

					$data['status'] = 1; // I assume that when status is success then I can reload the page / or do some redirection 
			}
			else 
			{	
					$data['errorMessage'] =  trans('messages.LOGIN_LOGIN_DOES_NOT_EXIST');
			}

		}

		response()->json($data);
	}

How to Setup Outlook 2007 to Check Your Email

  1. Start Outlook.
  2. On the Tools menu, click Account Settings.
  3. On the Email tab, click New.
  4. In the Add New Email Account dialog box, click Microsoft Exchange, POP3, IMAP, or HTTP, and then click Next.
  5. Configure the new email account. You can configure the new email account automatically or manually.
    • To configure the new email account automatically, follow these steps under Auto Account Setupin the Add New Email Account dialog box:
      1. In the Your Name box, type your full name.
      2. In the Email Address box, type your email address.Your ISP provides this information. Your email address usually takes the form of a combination of your first and last name and the name of your ISP, separated by the at sign (@) and periods.

        For example, Sachin Karnik uses an ISP that is named Contoso.com. The ISP may assign an email address of skarnik@contoso.com.

      3. In the Password box, type the password that your ISP provided.
      4. In the Retype Password box, retype the password, and then click Next to begin the Auto Account Setup process.Outlook 2007 will try to automatically configure your account settings and server settings. If your account is successfully configured, the Add New Email Account dialog box indicates that the account was created successfully. This dialog box also indicates the type of email server to which you successfully connected.
      5. Click Finish, and then click Close to complete the account setup.Note If automatic configuration fails, the account must be configured manually.
    • To configure the new e-mail account manually, follow these steps in the Add New E-mail Accountdialog box:
      1. Click to select the Manually configure server settings or additional server types check box, and then click Next.
      2. Click Internet Email, and then click Next.
      3. Under User Information, follow these steps:
        1. In the Your Name box, type your full name.
        2. In the Email Address box, type your full e-mail address.Your ISP provides this information. Your email address usually takes the form of a combination of your first and last name and the name of your ISP, separated by the at sign (@) and periods.

          For example, Sachin Karnik uses an ISP that is named Contoso.com. The ISP may assign an e-mail address of skarnik@contoso.com.

      4. Under Server Information, click the type of email account that you have in the Account Type box.
        • If you clicked POP3 or IMAP in the Account Type box, follow these steps:
          1. In the Incoming mail server box, type the name of the server. This is the server that holds your messages before you download them to the computer. Type the server name in lowercase letters. The name may be in the form of “mail.contoso.com.” Or the name may be in the form of an IP address, such as 172.12.0.0.
          2. In the Outgoing mail server (SMTP) box, type the name of the outgoing email server. Type the server name in lowercase letters. The name may be in the form of “mail.contoso.com.” Or, the name may be in the form of an IP address, such as 172.12.0.0.
        • If you clicked HTTP in the Account Type box, follow these steps:
          1. In the HTTP Service Provider box, click the appropriate service provider for this account. For example, click one of the following:
            • Hotmail
            • MSN
            • Other
          2. If you clicked Other in the HTTP Service Provider box, type the URL to the mailbox in the Server URL box.
      5. Under Logon Information, follow these steps:
        1. In the User Name box, type your user name. The user name is usually the part of your email address to the left of the at sign (@).
        2. In the Password box, type the password that your ISP provided.
        3. If you want Outlook to remember your email account password, click to select theRemember password check box.
      6. If your ISP requires it, click to select the Require logon using Secure Password Authentication (SPA) check box to log on by using Secure Password Authentication.
      7. Click Test Account Settings. This feature calls a dialog box that displays, in a step-by-step manner, each phase of the testing of the configuration that you entered. When you click Test Account Settings, the following process occurs:
        • The connectivity of the system to the Internet is confirmed.
        • You are logged on to the SMTP server.
        • You are logged on to the POP3 server.
        • It is determined whether the POP3 server must be logged on to first. If it is required, Outlook automatically sets the Log on to incoming mail server before sending mailoption.
        • A test message is sent. This message explains any changes that Outlook made to the initial setup.
      8. If you want to modify your e-mail account any more, click More Settings to open theInternet Email Settings dialog box.
      9. Click Next, and then click Finish