Archive

Archive for March, 2010

Zend mail

March 3, 2010 Leave a comment

Zend_Mail:

$mail = new Zend_Mail();
$mail->setBodyText('Our body of the email.');
$mail->setFrom('you@yourdomain.com', 'Name of yours');
$mail->addTo('to@anotherdomain.com', 'Others name');
$mail->setSubject('Subject of this email');
$mail->send();

Categories: centOS, Fedora 12, PHP, Unix/Linux, Zend

Zend zend_layout

March 3, 2010 Leave a comment

Zend_Layout:

tips1:

// application/layouts/scripts/default.phtml

$this->_helper->layout()->setLayout(‘default’);

tips2:

$this->_flashMessenger = $this->_helper->getHelper(‘FlashMessenger’);

$this->_flashMessenger->addMessage(‘We did something in the last request’);

$this->view->messages = $this->_flashMessenger->getMessages();

tips 3:

// Controller > put >

$response = $this->getResponse();

// application/views/scripts/sidebar.phtml

$response->insert(‘sidebar’, $this->view->render(‘sidebar.phtml’));

// layout put this:

      <?php echo $this->layout()->sidebar; ?>
Categories: centOS, Fedora 12, PHP, Unix/Linux, Zend

Zend zend_view

March 3, 2010 Leave a comment

Tips for the Zend_View

How to zend view?

tips 1:

Disable auto render

$this->_helper->viewRenderer->setNoRender(); //suppress auto-rendering

header(””);

echo $pdf/csv;

tips 2:

Helpers to put custom functions

default path Zend/view/helpers

tips 3:

You can tell Zend_View to look in other locations using the setHelperPath() and addHelperPath() methods

Bootstrap.php
$view = new Zend_View();
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($view);
$view->addHelperPath('../application/views/helpers', 'My_View_Helper');
...
  /application/views/helper/GetActionDescHelper.php

views:

echo $this->getActionDescHelper($var);
Categories: centOS, Fedora 12, PHP, Unix/Linux, Zend

Zend Registry global

March 3, 2010 Leave a comment

How to zend register a variable? Like global.

1. Zend_Register::set(variable, value)

<?php

class IndexController extends Zend_Controller_Action

{

public function init()

{

Zend_Registry::set(‘myglobal’, ‘/var/log/messages.log’);

}

public function indexAction()

{

if (Zend_Registry::isRegistered(‘myglobal’)){

echo Zend_Registry::get(‘myglobal’);

}else{

echo ‘Sorry – register it or throw error’;

}

}

2. We can use in our view

Zend_Registry::get(‘myglobal’);

Categories: centOS, Fedora 12, PHP, Unix/Linux, Zend

Zend zend_db sql mysql

March 2, 2010 Leave a comment

How to zend sql?

1. Free hand SQL, make it FREE!

<?php

class IndexController extends Zend_Controller_Action

{

public function init()

{

// Instant db access

$db = Zend_Db::factory(‘Pdo_Mysql’,

array(

‘host’ => ‘localhost’,

‘username’ => ‘root’,

‘password’ => ‘00000’,

‘dbname’ => ‘myzf’

));

Read more…

Zend get post request

March 2, 2010 Leave a comment

How to use traditional get / post/ request?

<?php

class IndexController extends Zend_Controller_Action

{

public function init()

{

// GET – method

// http://localhost:8008/myzf/public/index/add/id/value

echo $this->_getParam(‘id’, false) . ‘ or ‘ . $this->getRequest()->getParam(‘id’);

// POST – method

echo $this->_request->getPost(‘id’);

// or

//$filter = new Zend_Filter_StripTags();

//$data[‘news_content’] = $filter->filter($this->_request->getPost(‘news_content’));

}

}

Categories: centOS, PHP, Zend

Zend debug

March 2, 2010 Leave a comment

How to debug my get/post etc?

1. Zend_Debug or Zend_Config_Ini

<?php

class IndexController extends Zend_Controller_Action

{

public function init()

{

Zend_Debug::dump($this->_request->getPathInfo());

$config = new Zend_Config_Ini(‘/var/www/html/myzf/application/configs/application.ini’, ‘production’);

//print_r ($config);

// includePaths.library = APPLICATION_PATH “/../library”

echo $config->includePaths->library;

// Output: /var/www/html/myzf/application/../library

}



Categories: centOS, PHP, Zend