Feb
9
2014

doSelectStmt in symfony 1.2

doSelectStmt in symfony 1.2

{code type=codetype}
$cd = new Criteria();
$cd->clearSelectColumns();
$cd->addSelectColumn(‘SUM(‘ . TablePeer::QTY . ‘) as sumqty’);
$stmt = TablePeer::doSelectStmt($cd);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo $row['sumqty'];
{/code}

Pinterest

Feb
9
2014

Run custom query in symfony 1.2 with propel

Sometimes we require to execute complex query in symfony 1.2 with propel. For this following code can be used.

{code type=codetype}
$conn = Propel::getConnection();
$query = “Select * from table”
$statement=$conn->prepare($query);
$statement->execute();
$rowObj = $statement->fetch(PDO::FETCH_OBJ);
{/code}

$rowObj will have result of your given query. You can check it via var_dump or print_r and show it as you want.

Pinterest

Feb
2
2014

select all checkbox code in jquery

sometimes we have multiple checkbox fields in form and require to select all and deselect all. Following is code to select and deselect.

{code type=codetype}
$(“#selectAll”).click(function(){
$(“.chkboxes”).prop(“checked”,$(“#selectAll”).prop(“checked”))
});
$(“.chkboxes”).click(function(){
if($(“.chkboxes”).length == $(“.chkboxes:checked”).length) {
$(“#selectAll”).prop(“checked”, true);
} else {
$(“#selectAll”).removeAttr(“checked”);
}
});
{/code}

Pinterest

Feb
2
2014

referer redirect method in symfony.

{code type=codetype}
$this->redirect($request->getReferer());
{/code}

This is very useful method and used to redirect back to sender page.

Pinterest

Dec
8
2013

How to register Ruby environments with pik?

pik add command is used to register your installed ruby environments with pik. For example, I have Ruby 1.9.3, and 2.0.0 installed on my windows, so I used the following in a Command Prompt:

{code type=codetype}
> pik add C:\Ruby193\bin
INFO: Adding: [ruby-]1.9.3-p392
Located at: C:\Ruby193\bin

> pik add C:\Ruby200\bin
INFO: Adding: [ruby-]2.0.0-p0
Located at: C:\Ruby2000\bin
{/code}

Use the pik list command to list all the ruby interpreters registered with pik:

{code type=codetype}
> pik list
ruby-1.9.3-p392
ruby-2.0.0-p0
{/code}
Make a default Ruby

The pik use command will allow you to switch between your registered ruby interpreters:

{code type=codetype}
> pik use ruby-2.0.0-p0
> ruby -v
ruby 2.0.0p0 (2013-02-024) [i386-mingw32]
{/code}

Add the –default parameter to set one version as the default:

{code type=codetype}
> pik use ruby-1.9.3-p392 –default
{/code}

You can use the pik default command to switch to this version:

{code type=codetype}
> pik default
> ruby -v
ruby 1.9.3p392 (2013-02-022) [i386-mingw32]
{/code}

When you open a command prompt, pik might not automatically loaded, so you will notice that there is no default ruby loaded:

Run the pik default command to load pik or add one particular Ruby interpreter to your user or system PATH environment variable from Control Panel -> System -> Advanced -> Environment Variables

set enviornment variable

Pinterest

Oct
26
2013

How to enable debug mode in joomla?

Sometimes we require troubleshooting for joomla cms based website. For this it is useful to enable joomla debug mode by enabling it website will be in debug mode. Enabling the debug mode allows you to see how joomla rendering your website. To enable debug mode you need to follow following steps.

  1. Login to joomla administrator backend
  2. Click on Site -> Global Configuration
  3. On “Global Configuration” page click no “System Tab”
  4. On right side under Debug Settings click on Debug System : Yes
  5. Now click on “Save & Close”

Now debug mode is enabled. You can see debug information at bottom of website as it typically placed at the bottom of the template.

To disable debug, just change Debug system to No and Click “Save & Close”.

Pinterest

Oct
18
2013

array_reverse in PHP

PHParray_reverse is one of array functions in php. It takes an input array and returns a new array with the order of the elements reversed. It can take two parameters first is array that need to be in reverse order and other is optional bool type “preserve_keys”, if it set to true then numeric key will be preserved but non numeric keys will not be affected and will always preserved.

Example 1:
{code type=codetype}
< ?php
$str = array("asdf", "xcvc","asf", "rtert", "gfgh", "cvcb");
print_r(array_reverse($str));
?>
{/code}

Output:{code type=codetype}
Array
(
[0] => cvcb
[1] => gfgh
[2] => rtert
[3] => asf
[4] => xcvc
[5] => asdf
){/code}

Pinterest

Aug
5
2013

Show html field type file via generator.yml in symfony 1.2 propel.

I worked on a project in which I created a module in admin which has image field that will be uploaded by admin for this field must have input field type file.

That module was generated by symfony 1.2 using with propel. By default image field was shown as text field. I search over internet to make it as input type file so image can upload from it but didn’t find any accurate results but doing some search in symfony 1.2 library I got idea to implement it, just need to add following line in generator.yml under fields section of edit section.

Open you generator.yml file of your module.

{code type=codetype}
edit:
fields:
logo: {type: admin_input_file_tag,upload_dir: image_dir_to_upload,params: include_link=image_dir_to_upload include_remove=true}
{/code}

Save it and clear your cache and check it in your browser.

Note: replace image_dir_to_upload with your directory name where you want to upload image.

That’s it.

Pinterest

Aug
4
2013

How to install ruby on rails with sqlite3 on windows 7?

I have started working on ruby on rails and need to install it on windows 7. I searched on google and found installation help on different sites that is not complete for all packages, so I am writing here and hope it will be helpful.

I downloaded packages related to ruby on rails that are pik-0.3.0.pre, rubyinstaller-2.0.0-p247-x64, DevKit-mingw64-64-4.7.2-20130224-1432-sfx, sqlite-autoconf-3071700.tar.gz.

pik-0.3.0.pre is a tool to manage multiple versions of ruby on windows and it can be used from git bash, windows command line.

Install pik

First install pik anywhere in your system. I installed on D drive, so when successfully installed, open your command line(cmd.exe). Run following command

>pik help commands

Note: if pik is undefined command then check your environment variable. You have to create environment variable for this.

Pinterest

Jul
20
2013

jQuery addClass and removeClass.

addClass() and removeClass() are very useful methods from jquery. addClass() method used to add one or more css class in selected element while removeClass() is used to remove class.

I used addClass() to show block as selected and removeClass() method to deselect block that was previously clicked, blocks were dynamically created. Following is code.

{code type=codetype}
<script>
$(function(){
$(“.blocks”).click(function() {
var ids;
var previous = “”;
previous = $(“#previous”).val();
if(previous !=”"){
$(previous).removeClass(“sel”);
}
ids = $(this).attr(“id”);

$(“#”+ids).addClass(‘sel’);
$(“#previous”).val(“#”+ids);
});
});
</script>
{/code}

Demo

Pinterest

Pages:12345678»