Posts Tagged ‘PHP’
30
Oct

getMessage() 

gets the exception’s message

 
 

getCode(

returns a numerical code that represents the exception

 
 

getFile()

returns the file where the exception was thrown

 
 

getLine() 

returns the line number in the file where the exception was thrown

 
 

getTrace()

returns the an array of the backtrace() before the exception was thrown

 
 

getPrevious() 

returns the exception thrown before the current one, if any

 
 

getTraceAsString()

returns the backtrace() of an exception as a string instead of an array

 
 

__toString() 

returns the whole exception as a string. Is overrideable.

 
 

 
 

, , , , , , , , ,

19
Oct

A php custom function to check the argument is number or string:

function is_number_or_string($val){

if( ((int) $val + 0 ) > 0 ){
return "Number";
}else{
return "String";
}
}

, , , ,

03
Oct

Assuming you know how to create a custom module, consider a case where you need to create a URL for your module. Follow these steps:

In your module’s config.xml file:

<modules>
.....
</modules>
<global>
....
</global>
<frontend>
	<routers>
		<schurl> --> name that will used in the URL
			<use>standard</use>  ---> standard means its a frontend url; admin will mean it is a backend url
			<args>
				<module>Mage_Schogini</module>  ---> which is the module to be used
				<frontName>schurl</frontName>   ---> name that will used in the URL
			</args>
		</schurl>
	</routers>
</frontend>
<default>
.....
</default>

Create a controller file TestController.php in your module’s controller folder like this (as you may have guessed, my modules name is Schogini):

class Mage_Schogini_TestController extends Mage_Core_Controller_Front_Action
{
	public function showmsgAction()
	{
		echo 'Here';
	}
}

This is what happens when you browse this URL
http://mymagentostore.com/schurl/test/showmsg/

  • schurl tells that the controller to check is Mage_Schogini (the name that is specified in the config file in the section: args > module)
  • test tells that controllers/TestController.php file must be checked
  • showmsg tells that showmsgAction() method must be called.

Hence, it will look for the method showmsg() inside the Mage_Schogini_TestController class

, , , , , , , , , , , , , ,

26
Aug

You need to explicitly specify the x-template for the mask. So, your form definition should look something like this:

{
	xtype: 'form',
	// TEMPLATE OF THE MASK
	waitTpl: '<div class="x-mask-loading"><div class="x-loading-spinner"><span class="x-loading-top"></span><span class="x-loading-right"></span><span class="x-loading-bottom"></span><span class="x-loading-left"></span></div><div class="x-loading-msg">{message}</div></div>'),
	items: [{....]
}

And the message you want to show you can decide in the form submit button handler where you will call the form submit like this:

myFrm.submit({
	url: 'somescript.php',
	method: 'POST',
	waitMsg: 'Processing...', ---> MESSAGE TO DISPLAY IN MASK
	success: function (frm, res)  {
		alert('Form submitted');
	},
	failure: function (frm, res) {
		alert('Form submit error');
	}
});

, , , , , , , , , , , , , ,

29
Jul

The zip_entry_open() function opens a zip archive entry for reading. This function returns TRUE on success, or FALSE on failure.

syntax:zip_entry_open(zip,zip_entry,mode)

zip –> Required. Specifies the zip resource to read (a zip file opened with zip_open() )

zip_entry –>Required. Specifies the zip entry resource to open (a zip entry opened with zip_read() )

mode–>Optional. Specifies the type of access you require to the zip archive.

<?php

$zip = zip_open(“test.zip”);

if ($zip)

{

while ($zip_entry = zip_read($zip))

{

echo “<p>”;

echo “Name: ” . zip_entry_name($zip_entry) . “<br />”;

if (zip_entry_open($zip, $zip_entry))

{

// some code

}

echo “</p>”;

}

zip_close($zip);

}

?>

, , , , , , , , , , , , , ,

29
Jul

There are several options:

imagecopyresampled() using GD
Imagick::resizeImage() using ImageMagick

,

25
Jul

Here is the code for a simple form submit in Sencha Touch:

var myForm = new Ext.Panel({
	layout: 'card',
	dockedItems: [{
		xtype: 'toolbar',
		docked: 'top',
		title: 'Test Form'
	}],
	items: [{
		xtype: 'form',
		title: 'My Form',
		id: 'register',
		items: [{
			xtype: 'fieldset',
			title: 'Personal Info',
			instructions: 'Some instruction for personal info',
			defaults: {
				labelWidth: '40%'
			},
			items: [{
				xtype: 'datepickerfield',
				name: 'dob',
				label: 'Date of birth',
				required: true,
				useClearIcon: true,
				picker: {yearFrom: 1900}
			}, {
				xtype: 'selectfield',
				name: 'gender',
				label: 'Gender',
				required: true,
				useClearIcon: true,
				options: [{
					text: 'Male',
					value: 'male'
				}, {
					text: 'Female',
					value: 'female'
				}]
			}, {
				xtype: 'textfield',
				name: 'phone_number',
				label: 'Phone number',
				placeHolder: 'Enter..',
				required: false,
				useClearIcon: true,
			}]
		},
		{
			xtype: 'fieldset',
			title: 'Login Info',
			instructions: 'Some instruction for login info',
			defaults: {
				labelWidth: '40%'
			},
			items: [{
				xtype: 'emailfield',
				name: 'email',
				label: 'Email',
				placeHolder: 'me@abc.com',
				required: true,
				useClearIcon: true,
			}, {
				xtype: 'passwordfield',
				name: 'password',
				label: 'Password',
				required: true,
				useClearIcon: true,
			}, {
				xtype: 'passwordfield',
				name: 'repeat_password',
				label: 'Re-type password',
				required: true,
				useClearIcon: true,
			}]
		}, {
			xtype: 'button',
			text: 'Register',
			scope: this,
			handler: function (b, e) {
				var form = Ext.getCmp('register');
				form.submit({
					url: 'testform.php',
					method: 'POST',
					success: function (frm, res)  {
						alert('Form submitted: ' + res.customfield);
					},
					failure: function (frm, res) {
						alert('Form no submit!');
					}
				});
			}
		}
	}]
});

 

This is testform.php:
It is very important to send success => true
If, success is not defined or not equal to true then it will be considered as a form submit error.

<?php
$response = array('success' => true, 'customfield' => 'custom value');

echo json_encode($response);

?>

, , , , , , , , , , , , , ,

30
Jun

$rawPhoneNumber = "800-555-5555";

$phoneChunks = explode("-", $rawPhoneNumber);

echo "Raw Phone Number = $rawPhoneNumber <br />";

echo "First chunk = $phoneChunks[0]<br />";

echo "Second chunk = $phoneChunks[1]<br />";

echo "Third Chunk chunk = $phoneChunks[2]";

output

Raw Phone Number = 800-555-5555

First chunk = 800

Second chunk = 555

Third Chunk chunk = 5555

 

, , , , , , ,

30
Jun

$numberedString = "1234567890"; // 10 numbers from 1 to 0

$fivePos = strpos($numberedString, "5");

echo "The position of 5 in our string was $fivePos";

output

The position of 5 in our string was 4

 

 

, , ,

30
Jun

$pieces = array(“Hello”, “World,”, “I”, “am”, “Here!”);

$gluedTogetherSpaces = implode(” “, $pieces);

$gluedTogetherDashes = implode(“-”, $pieces);

for($i = 0; $i < count($pieces); $i++){

echo “Piece #$i = $pieces[$i] <br />”;

}

echo “Glued with Spaces = $gluedTogetherSpaces <br />”;

echo “Glued with Dashes = $gluedTogetherDashes”;

 

output

Piece #0 = Hello

Piece #1 = World,

Piece #2 = I

Piece #3 = am

Piece #4 = Here!

Glued with Spaces = Hello World, I am Here!

Glued with Dashes = Hello-World,-I-am-Here!

 

, , , , , , , ,