Posts in php

SQL to query categories with no childrens in WordPress

abril 2nd, 2012 Posted by mysql, php, wordpress 0 thoughts on “SQL to query categories with no childrens in WordPress”
SELECT wp_terms.name, wp_terms.term_id
FROM wp_terms
INNER JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id
WHERE wp_term_taxonomy.taxonomy = “category”
AND wp_terms.term_id NOT
IN (
SELECT DISTINCT parent
FROM `wp_term_taxonomy`
WHERE parent <>0
)
LIMIT 0 , 30

Smarty first item of array

enero 6th, 2012 Posted by php, smarty 0 thoughts on “Smarty first item of array”
{foreach from=$items key=myId item=i name=foo} 

{/foreach}
{if $smarty.foreach.foo.first}LATEST{else}{$myId}{/if} {$i.label}

Prestashop | This module cannot be transplanted to this hook.

enero 6th, 2012 Posted by php, prestashop 0 thoughts on “Prestashop | This module cannot be transplanted to this hook.”

If you are trying to place a Prestahsop Module in some hook, and you are getting this error: “This module cannot be transplanted to this hook.” you can fix it modifying the module’s php.

For example if you are trying to place the Categories Block in the “Top of Pages” and you can’t. Open the file: /modules/blockcategories/blockategories.php and add this function:

public function hookTop($params)
{
        return $this->hookLeftColumn($params);

}

Cómo utilizar Zend_Auth_Adapter con Web Services

mayo 27th, 2011 Posted by php, web services, zend framework 0 thoughts on “Cómo utilizar Zend_Auth_Adapter con Web Services”
<?
class My_Auth_Adapter implements Zend_Auth_Adapter_Interface {

const OK_RESPONSE = 'OK';
const KO_RESPONSE = 'KO';

private $_username = '';
private $_password = '';
private $_data = null;

public function setIdentity($username) {
$this->_username = $username;
}

public function setCredential($password) {
$this->_password = $password;
}

/**
* Authenticate the user
*
* @return Zend_Auth_Result
*/
public function authenticate() {
$endpointLoginAuthor = Zend_Registry::get('config')->endpoint->userService->loginAuthor;

$client = new Zend_Rest_Client($endpointLoginAuthor);
$client->username($this->_username);
$client->password($this->_password);

$response = $client->get();

$authenticated = ($response->ResponseDescription == $this::OK_RESPONSE);
$authResult = Zend_Auth_Result::FAILURE;

$authMessages = array();

if ($authenticated){
// user is authenticated, overwrite the auth result:
$authResult = Zend_Auth_Result::SUCCESS;
$this->_data = $response->Author;
} else {
// Couldn't authenticate the user, set a message:
$authMessages[] = 'Datos de acceso inválidos.';
}

// return the result:
return new Zend_Auth_Result( $authResult, $this->_username, $authMessages );

}

/**
*
* @param <type> $returnColumns
* @param <type> $omitColumns
* @return <type> SimpleXMLObject
*/
public function getResultRowObject($returnColumns = null, $omitColumns = null){
// If no data is set, return false:
if (!$this->_data) {
return false;
}

return $this->_data;
}
}

?>


Cómo setear desde un Controller variables de un Zend_Layout

abril 26th, 2011 Posted by php, zend framework 0 thoughts on “Cómo setear desde un Controller variables de un Zend_Layout”

En el controller:
 

class MyController extends Zend_Controller_Action {
    public function init() {
        $this->_helper->layout->getView()->myVar = 'Value';
    }
}

En el layout.phtml

<? echo $this->myVar; ?>

Como debuggear con MAMP y Netbeans

abril 26th, 2011 Posted by apache, mac, netbeans, php 0 thoughts on “Como debuggear con MAMP y Netbeans”

1. Desde la consola:

vi /Applications/MAMP/conf/php5.3/php.ini

2. Buscar [xdebug] y agregar:

[xdebug]
xdebug.default_enable=1

xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1

zend_extension=”/Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so”

3. Reinicar MAMP
4. En Netbeans click derecho sobre el proyecto -> “Debug”

Cómo setear el include path de php para un determinado Virtual Host de Apache

abril 24th, 2011 Posted by apache, php 0 thoughts on “Cómo setear el include path de php para un determinado Virtual Host de Apache”

Se puede hacer editando el archivo http.conf

Por ejemplo:

<VirtualHost *>
ServerName mysite.local
DocumentRoot "/path/to/site"
<Directory "/path/to/site">
php_value include_path ".:/include/path/"
</Directory>
</VirtualHost>

MAMP carga muy lento cuando se llama a Zend_Session::start();

abril 24th, 2011 Posted by php, zend framework 0 thoughts on “MAMP carga muy lento cuando se llama a Zend_Session::start();”

El session handler tiene algún problema al intentar guardar las sessiones en disco.

Entonces se puede utilizar Zend para utilizar otro adapter y por ejemplo guardar las sesiones en una BD.

// Comment
$db = Zend_Db::factory('Pdo_Mysql', array(
    'host'        =>'localhost',
    'username'    => 'dbuser',
    'password'    => '****',
    'dbname'    => 'mydb'
));

//you can either set the Zend_Db_Table default adapter
//or you can pass the db connection straight to the save handler $config
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$config = array(
    'name'           => 'session',
    'primary'        => 'id',
    'modifiedColumn' => 'modified',
    'dataColumn'     => 'data',
    'lifetimeColumn' => 'lifetime'
);

//create your Zend_Session_SaveHandler_DbTable and
//set the save handler for Zend_Session
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));

// start session
Zend_Session::start();

How to get twitter statuses in json format

noviembre 7th, 2010 Posted by apis, php, twitter 0 thoughts on “How to get twitter statuses in json format”
file_get_content(“http://api.twitter.com/1/statuses/user_timeline.json?screen_name=carna3d”);

Cómo instalar apache2 + mysql + php

julio 26th, 2010 Posted by apache2, linux, mysql, php 0 thoughts on “Cómo instalar apache2 + mysql + php”

sudo aptitude update
sudo aptitude upgrade
sudo aptitude install mysql-server
sudo /usr/bin/mysqladmin -u root password pon_tu_pass
sudo aptitude install apache2
sudo aptitude install php5
sudo aptitude install libapache2-mod-auth-mysql
sudo aptitude install php5-mysql
sudo /etc/init.d/apache2 restart
sudo gedit /var/www/test.php

Copyright © 2018 programadorfreelanceargentina.com

Programador Freelance Argentina