Archivo de la etiqueta: Zend Framework

Agregar mas de un destinatario al enviar Mails con Zend_Mail – Zend Framework

Supongamos el siguiente ejemplo de Zend_Mail


$mail = new Zend_Mail()

$mail->setBodyText('This is the text of the mail.');

$mail->setFrom('somebody@example.com', 'Some Sender');

$mail->addTo('somebody_else@example.com', 'Some Recipient');

$mail->addCc('somebody_else@example.com', 'Some Recipient');

$mail->addBcc('somebody_else@example.com', 'Some Recipient');

$mail->setSubject('TestSubject');

$mail->send();

Si queremos agregar mas de un destinatario al addTo(), addCc() y al addBcc() lo podemos hacer por medio de un array de direcciones de correo. En el caso del addTo() y el addCc(), estas arrays pueden ser asociativas, y en estas la key es el nombre del destinatario. Es decir:


$toRecipients = array('Some Recipient' => 'somebody_else@example.com', 'Other' => 'other@example.com');

$hideRecipients = array('one@example.com', 'two@example.com');

$mail->addTo($toRecipients);

$mail->addCc($toRecipients);

$mail->addBcc($hideRecipients);

+ Información: http://framework.zend.com/manual/1.12/en/zend.mail.adding-recipients.html

Creando consultas Select con Zend_Db_Select – PHP Tips

Uno de los frameworks con los cuales mas me gusta trabajar es con ZendFramework, sobre todo con las funciones de conexión y consulta MySQL, ya que el uso de estas me simplifica el trabajo. Hoy voy a explicar un poco el uso del Zend_Db_Select en la versión de ZendFramework 1.12. Vamos a suponer que la conexión a la base de datos ya la tenemos configurada.


// $db es la conexión a la base de datos

$select = $db->select();

$select->from('mitable');

$select->where('id LIKE ?' => $id);

$stmt = $select->query();

$result = $stmt->fetchAll();

Este seria un ejemplo básico de selección de un dato de una tabla y devolver todos los datos con ese Id.

Para mas información y mas métodos http://framework.zend.com/manual/1.12/en/zend.db.select.html

 

 

 

Bugzilla Webservice client con Zend Framework

Este es un ejemplo de como conectarnos al servidor de bugzilla y enviar el Bug con la libreria Zend_XmlRpc

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
$server = 'http://bugzilla.mydomain.com/xmlrpc.cgi';
$client = new Zend_XmlRpc_Client( $server );
// Create the http client
$httpClient = new Zend_Http_Client();
$httpClient->setCookieJar();
$client->setHttpClient( $httpClient );
// Bugzilla Login
$params = new Zend_XmlRpc_Value_Struct( 
		array(
			'login' => 'bugzilla@mydomain.com', 
			'password' => 'mypassword', 
			'remember' => 1
			)
		);
$request = $client->call('User.login', $params );
// Create the Bug
$bugParams = new Zend_XmlRpc_Value_Struct(
		array( 'product' => 'MyApp',
				'component' => 'Main',
				'summary' => 'Bug Sumary',
				'version' => '1.0',
				'description' => 'This is the description' 
			  )
		);
$result = $client->call( 'Bug.create', $bugParams );
// Logout
$result = $client->call( 'User.logout' );

+Info XmlRpcClient Zend Framework
Bugzilla Webservice API

Comandos Zend Framework Command Line Console Tool

Dejo aquí los comandos de la zf tool en la versión de Zend Framework 1.11.11

Zend Framework Command Line Console Tool v1.11.11
Usage:
    zf [--global-opts] action-name [--action-opts] provider-name [--provider-opts] [provider parameters ...]
    Note: You may use "?" in any place of the above usage string to ask for more specific help information.
    Example: "zf ? version" will list all available actions for the version provider.

Providers and their actions:
  Version
    zf show version mode[=mini] name-included[=1]
    Note: There are specialties, use zf show version.? to get specific help on them.

  Config
    zf create config
    zf show config
    zf enable config
    Note: There are specialties, use zf enable config.? to get specific help on them.
    zf disable config
    Note: There are specialties, use zf disable config.? to get specific help on them.

  Phpinfo
    zf show phpinfo

  Manifest
    zf show manifest

  Profile
    zf show profile

  Project
    zf create project path name-of-profile file-of-profile
    zf show project
    Note: There are specialties, use zf show project.? to get specific help on them.

  Application
    zf change application.class-name-prefix class-name-prefix

  Model
    zf create model name module

  View
    zf create view controller-name action-name-or-simple-name module

  Controller
    zf create controller name index-action-included[=1] module

  Action
    zf create action name controller-name[=Index] view-included[=1] module

  Module
    zf create module name

  Form
    zf enable form module
    zf create form name module

  Layout
    zf enable layout
    zf disable layout

  DbAdapter
    zf configure db-adapter dsn section-name[=production]

  DbTable
    zf create db-table name actual-table-name module force-overwrite
    Note: There are specialties, use zf create db-table.? to get specific help on them.

  ProjectProvider
    zf create project-provider name actions

UTF-8 Por defecto en nuestras conexiones PHP:MySQL Tips

Conexión a MySQL clasica

$con = mysql_connect ("localhost","user","password") or die (mysql_error()); // establecemos la conexion
mysql_set_charset('utf8', $con); // establecemos el Charset
$dbname = "midb"; 
mysql_select_db($dbname, $con); // establecemos la base de datos por defecto
// Consulta de ejemplo
$sql = "Select * from mitabla";
// como mysql_db_query esta deprecated tenemos que acostumbrarnos a usar el mysql_query
$consulta = mysql_query($sql,$con); // asi ya no es necesario usar el $dbname en todas las consultas

Conexion a MySQL con Zend_Dd

require_once 'Zend/Loader/Autoloader.php'; // Para que me haga la autocarga de Zend
Zend_Loader_Autoloader::getInstance(); // Establece la autocarga
$pdoParams = array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8;');
$this->db = Zend_Db::factory('Pdo_Mysql',array(
    'host'  =>  'localhost',
    'username'  =>  'user',
    'password'  =>  'password',
    'dbname'    =>  'midb',
    'driver_options' => $pdoParams
));