Pages

Sunday, June 26, 2011

Transactions Shortcut in Cakephp

Add the following functions in app/models/AppModel

function begin()
{
$db=&ConnectionManger::getDataSource
$db->begin($this);
$this->useDbConfig;
}

function commit()
{
$db->commit($this);
}

function rollback()
{
$db->rollback($this);
}

Now in you controller
Use
$this->Model->Begin()
$this->Model->commit();
$this->Model->rollback();

Cakephp:To run an ajax on page load use

$this->Ajax->remoteFunction($options);

where $options are 'url'=>controller,action
'update'=>
'with'=>Form.SearlizeElements(new array($("BillClientId")))');

Using Pear Framework in Cakephp

1. Copy the pear in the venders directory in the root(there are 2 one in app folder as well)

If you wish to use that one copy cake/config/paths to app/config/paths and change the following line

/**
* Path to the vendors directory.
*/
if (!defined('VENDORS')) {
define('VENDORS', CAKE_CORE_INCLUDE_PATH.DS.app.DS.'vendors'.DS);
}

After copying Pear now you have the framework its time to copy components

2.copy the package needed in the pear directory

Now we will create a path for our Pear package so that Cake can easily access that

For that copy cake/config/paths.php to app/config.paths.php add an entry after venders definition as follows

"define ('PEAR',VENDORS.'Pear'.DS)";

This defines a constant for PEAR path...

Now we need to set that path in our include path for that in your boot_strap file mark an entry as

ini_set("include_path",PEAR.PATH_SEPARATOR.ini_get("include_path"));

so path is now set in "include_path".

Next we need our controller to recognize this so just before start of controller or view(as per requirement)enter the following line

App::import('Vendor','Words',array('file'=>'../vendors/Pear/Numbers/Words.php'));

That's all now you can create an object of class and use it as follows

$numberconverter=new number_words();

echo $numberconverter->towords($grandtotal);

If your view is going blank on creation of object check that the import link on top of controller or view is correct.

Cakephp:send multople elements values in observe field

$options=>array('url'=>array('controller'=>'admin','action'=>'update_list'),'update'=>'divIdToUpdate','frequency'=>'0.2','with'=>'Form.serialize elements($('elementid1','elementid2,elementid3')));

echo $this->Ajax->observefield('Schedulepart',$options);

Cakephp:Image on clear Button

$this->Html->link($this->Html->image('button-clear.gif',array('alt'=>('clear',true),'border'=>'0'),array('onclick'=>"document.form.reset();return false;",'escape'=>'false)

Cakephp:Selecting Multiple Entries from a list

use the following code

$this->Form->select('Model.name',$listarray,'selectedvalue',array('multiple'=>'multiple','size'=>'5');

CakePHP:Button Image does not appear

Button Image does not appears in fact html tags are converted to escape sequences

When ever an button image is inserted tags appear as in written instead of showing image

Sunday, May 1, 2011

Fatal error: Maximum execution time of 30 seconds exceeded in

Fatal error: Maximum execution time of 30 seconds exceeded in
Faced this error while installing a PHP project on my webserver.The solution to This problem is simple Simply increase the Execution timeout in the Php.ini file till the time you are getting the error.

Search for these lines

; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 150

Bingo here you go

Thursday, February 24, 2011

Fatal error: Class 'Debugger' not found in when debug level set to 2 in core.php

Just started off with another RAD platform Cake PHP..and faced an issue so decided to share this fresh hard nut of my cake...

As I downloaded the version 2.0.0 of the Cake PHP RAD platform and copied it to my Apache's root...

And then there was a welcome message awaiting for me

Fatal error: Class 'Debugger' not found

I altered the Debugger value in php.ini file to 0 this problem went away..But I wanted the debugger level to be 2 so I started peeping into the websites for a solution and got a one liner

Add this:

App::import('Core', 'Debugger');

in app/config/bootstrap.php

I am still studying so will let you know more on this statement as I get back till now its a mere copy paste

Thursday, February 10, 2011

Items collection must be empty before using ItemsSource.

This error occurs when you try to add Children to a control which already has a item source as a result there is a lot of confusion to the parser regarding which one to choose.

Any children you add to the control are a part of its item collection consider for example

<listview margin="8,9,11,125" name="listView1" itemssource="{Binding}" minwidth="250" minheight="200" columnspan="2" rowspan="2">
<listview.view>
<gridview>
<gridviewcolumn header="ID" displaymemberbinding="{Binding Path=ID}"></gridviewcolumn>
<gridviewcolumn header="Company" displaymemberbinding="{Binding Path=Company}"></gridviewcolumn>
<gridviewcolumn header="Email" displaymemberbinding="{Binding Path=Email}"></gridviewcolumn>
<gridviewcolumn header="Website" displaymemberbinding="{Binding Path=Website}"></gridviewcolumn>
<gridviewcolumn header="Phone" displaymemberbinding="{Binding Path=Phone}"></gridviewcolumn>
<gridviewcolumn header="Address" displaymemberbinding="{Binding Path=Address}"></gridviewcolumn>
<gridviewcolumn header="Field of Development" displaymemberbinding="{Binding Path=Field}"></gridviewcolumn>
<gridviewcolumn header="Notes" displaymemberbinding="{Binding Path=Notes}"></gridviewcolumn>
</gridview>
</listview.view>
<Button Margin="0,0,-326.634,-49.995" Name="buttonReset" HorizontalAlignment="Right" Grid.Row="6" Width="99.99" Height="31.123" VerticalAlignment="Bottom" Click="buttonReset_Click">Reset</Button>
</listview>

Now here I have added a button in the last as a part of Item collection for the list view so it gives me that error

When I remove that code everything works fine.We cannot insert items and set items source at same time.