looping through the array in a reverse manner or reverse foreach in php

$array = array(‘foo’ => ‘bar’, ‘baz’, ‘bat’ => 2);
end($array);
while (key($array) !== null) {
echo key($array) .”: ” .current($array) . PHP_EOL;
prev($array);
}

Error levels and their values in php

Value Constant Description
2 E_WARNING Non-fatal run-time errors. Execution of the script is not
halted
8 E_NOTICE Run-time notices. The script found something that might be
an error, but could also happen when running a script normally
256 E_USER_ERROR Fatal user-generated error. This is like an E_ERROR set by
the programmer using the PHP function trigger_error()
512 E_USER_WARNING Non-fatal user-generated warning. This is like an E_WARNING
set by the programmer using the PHP function trigger_error()
1024 E_USER_NOTICE User-generated notice. This is like an E_NOTICE set by the
programmer using the PHP function trigger_error()
4096 E_RECOVERABLE_ERROR Catchable fatal error. This is like an E_ERROR but can be
caught by a user defined handle (see also set_error_handler())
8191 E_ALL All errors and warnings, except level E_STRICT (E_STRICT
will be part of E_ALL as of PHP 6.0)

Couldn’t get short alias for (

The below query didn’t worked for me and gave me the error “Couldn’t get short alias for ( re” and so i did removed the spaces from between every ‘or’ and brackets ‘(‘. i have added the modified query below the original query.

$restaurant = Doctrine_Query::create()
->select(‘re.*’)
->from(‘ReservationHoursSetting re’)
//->where(“re.id <> ? AND re.reservation_setting_id = ? AND ( (re.hr_from > {$hourFrom} AND re.hr_from < {$hourTo}) OR (re.hr_to > {$hourFrom} AND re.hr_to < {$hourTo}) )”, array($HourID, $restaurantSettingID) )
//->where(“re.id <> ? AND re.reservation_setting_id = ? AND ( ( re.hr_from BETWEEN {$hourFrom} AND {$hourTo} ) OR ( re.hr_to BETWEEN {$hourFrom} AND {$hourTo} ) OR ( {$hourFrom} BETWEEN re.hr_from AND re.hr_to )  OR ( {$hourTo} BETWEEN re.hr_from AND re.hr_to ) )”, array($HourID,$restaurantSettingID) )
->where(“re.id <> ? AND re.reservation_setting_id = ? “, array($HourID,$restaurantSettingID) )
->andWhere(“((re.hr_from > {$hourFrom}  AND re.hr_from< {$hourTo})

OR (re.hr_to > {$hourFrom} AND re.hr_to < {$hourTo})

OR (re.hr_to > {$hourFrom}  AND re.hr_from < {$hourFrom})

OR (re.hr_to < {$hourTo}  AND re.hr_from > {$hourTo})

OR (re.hr_to = {$hourTo}  AND re.hr_from = {$hourFrom}))”)
->fetchArray();

====================

$restaurant = Doctrine_Query::create()
->select(‘re.*’)
->from(‘ReservationHoursSetting re’)
//->where(“re.id <> ? AND re.reservation_setting_id = ? AND ( (re.hr_from > {$hourFrom} AND re.hr_from < {$hourTo}) OR (re.hr_to > {$hourFrom} AND re.hr_to < {$hourTo}) )”, array($HourID, $restaurantSettingID) )
//->where(“re.id <> ? AND re.reservation_setting_id = ? AND ( ( re.hr_from BETWEEN {$hourFrom} AND {$hourTo} ) OR ( re.hr_to BETWEEN {$hourFrom} AND {$hourTo} ) OR ( {$hourFrom} BETWEEN re.hr_from AND re.hr_to )  OR ( {$hourTo} BETWEEN re.hr_from AND re.hr_to ) )”, array($HourID,$restaurantSettingID) )
->where(“re.id <> ? AND re.reservation_setting_id = ? “, array($HourID,$restaurantSettingID) )
->andWhere(“((re.hr_from > {$hourFrom}  AND re.hr_from< {$hourTo}) OR (re.hr_to > {$hourFrom} AND re.hr_to < {$hourTo}) OR (re.hr_to > {$hourFrom}  AND re.hr_from < {$hourFrom}) OR (re.hr_to < {$hourTo}  AND re.hr_from > {$hourTo}) OR (re.hr_to = {$hourTo}  AND re.hr_from = {$hourFrom}))”)
->fetchArray();

add categories with images on homepage – magento

to add categories along with images on homepage

just add the code given below to your homepage from admininstration cms management.

{{block type="catalog/navigation" name="catalog.category" template="catalog/category/list.phtml"}}
Also you need to create a list.phtml file under “/app/design/frontend/default/default/template/catalog/category/list.phtml”
and add the below given code to it:
===========================================
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php $open
= $this->isCategoryActive($_category); ?>
<?php
$cur_category
=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
if (
$immagine = $this->getCurrentCategory()->getImageUrl()):
?>

<div style="float: left; padding-right: 30px; text-align: center;">
<
div class="linkimage">
<
p>
<
a href="<?php echo $this->getCategoryUrl($_category)?>">
<
img src="<?php echo $immagine ?>" alt="<?php echo $this->htmlEscape($this->getCurrentCategory()->getName()) ?>" width="135" height="135" />
<?php echo $_category->getName()?>
</a>
</
p>
</
div>
</
div>

<?php endif; ?>
<?php
endforeach; ?>

================================================

wamp server download – all versions

you can get all the versions of wamp server from the below given link:

http://sourceforge.net/projects/wampserver/files/

curl not working with https

Today i was facing this issue. I had implement rpxnow for open ID on a website a. which used CURL for xml services.

The implementation was working fine on our server. But when client moved teh code to their server it stopped working.

First i checked that CURL is enabled on their server, but CURL was working perfectly fine for urls like “http://www.google.com”. Then i found that the issue was with the “https” sites.

So this is what solved my issue:

Add the below code to your curl options:

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);

This solved my problem.

Regards,

samsami2u

http://www.avidindiainc.com

xml parser in php

There is a build in function in php using which you can parse xml file to an array. I have an example created for the same, and it goes as mentioned below:

$xmlString = $raw;
$xmlParser = xml_parser_create();
xml_parse_into_struct($xmlParser, $xmlString, $values, $main);
xml_parser_free($xmlParser);

print_r(‘<pre>’);
echo “<b>Main array</b><br>”;
print_r($main);
echo “<br>”;
echo “<b>Values array</b><br>”;
print_r($values);
print_r(‘</pre>’);

Thanks,

Sachin (http://www.avidindiainc.com)

setAuthenticated in symfony for frontend and backend

The problem:

i had two applications 1) frontend and 2) backend.

but when i login into backend i was automatically login into the frontend application.

The Solution:

the solution is simple you have to define the session name for both the application or atleast one. so that the sessions for both of them differ from each other.

you can define the session name in the “\apps\backend\config\factories.yml” file

here

cli:
controller:
class: sfConsoleController
request:
class: sfConsoleRequest
response:
class: sfConsoleResponse

test:
storage:
class: sfSessionTestStorage

all:
#  controller:
#    class: sfFrontWebController
#
#  request:
#    class: sfWebRequest
#
#  response:
#    class: sfWebResponse
#
#  user:
#    class: myUser
#
storage:
class: sfSessionStorage
param:
session_name: symfonyBack
#
#  view_cache:
#    class: sfFileCache
#    param:
#      automaticCleaningFactor: 0
#      cacheDir:                %SF_TEMPLATE_CACHE_DIR%

i have given a name for the backend application (symfonyBack).

database connection in symfony 1.0

There are two files that needs to be configure database connection in symfony 1.0:

Both the below files as found in <project>\config\         directory(folder)

1) database.yml:

all:
propel:
class:      sfPropelDatabase
param:
phptype:  mysql
hostspec: localhost
database: symfonycms
username: root
password:
#port: 80
encoding: utf8 # Default charset for table creation
#persistent: true # Use persistent connections

or as a short hand for the above

all:
propel:
class:      sfPropelDatabase
param:
phptype:  mysql
dsn: mysql://root:password@localhost/databas
#port: 80
encoding: utf8 # Default charset for table creation
#persistent: true # Use persistent connections

2)propel.ini

propel.targetPackage       = lib.model
propel.packageObjectModel  = true
propel.project             = symfonycms
propel.database            = mysql
propel.database.createUrl  = mysql://localhost/
propel.database.url        = mysql://root:@localhost/symfonycms

propel.addGenericAccessors = true
propel.addGenericMutators  = true
propel.addTimeStamp        = false

propel.schema.validate     = false

; directories
propel.home                    = .
propel.output.dir              = /var/www/production/sfweb/www/cache/symfony-for-release/1.0.20/sf_sandbox
propel.schema.dir              = ${propel.output.dir}/config
propel.conf.dir                = ${propel.output.dir}/config
propel.phpconf.dir             = ${propel.output.dir}/config
propel.sql.dir                 = ${propel.output.dir}/data/sql
propel.runtime.conf.file       = runtime-conf.xml
propel.php.dir                 = ${propel.output.dir}
propel.default.schema.basename = schema
propel.datadump.mapper.from    = *schema.xml
propel.datadump.mapper.to      = *data.xml

; builder settings
propel.builder.peer.class              = addon.propel.builder.SfPeerBuilder
propel.builder.object.class            = addon.propel.builder.SfObjectBuilder

propel.builder.objectstub.class        = addon.propel.builder.SfExtensionObjectBuilder
propel.builder.peerstub.class          = addon.propel.builder.SfExtensionPeerBuilder
propel.builder.objectmultiextend.class = addon.propel.builder.SfMultiExtendObjectBuilder
propel.builder.mapbuilder.class        = addon.propel.builder.SfMapBuilderBuilder
propel.builder.interface.class         = propel.engine.builder.om.php5.PHP5InterfaceBuilder
propel.builder.node.class              = propel.engine.builder.om.php5.PHP5NodeBuilder
propel.builder.nodepeer.class          = propel.engine.builder.om.php5.PHP5NodePeerBuilder
propel.builder.nodestub.class          = propel.engine.builder.om.php5.PHP5ExtensionNodeBuilder
propel.builder.nodepeerstub.class      = propel.engine.builder.om.php5.PHP5ExtensionNodePeerBuilder

propel.builder.addIncludes = false
propel.builder.addComments = false

propel.builder.addBehaviors = false