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

Zend sessions

March 2, 2010 Leave a comment

How to zend session? 

1. Make session/Modify session

class IndexController extends Zend_Controller_Action

{

public function init()

{

// $_SESSION[‘mysession’]

$this->mysession = new Zend_Session_Namespace(‘mysession’);

// $_SESSION[‘mysession’][‘one’] = hello;

$this->mysession->one = ‘Hello’;

}

public function indexAction()

{

$this->mysession->one .= ‘ added new’;

echo $this->mysession->one; // output: Hello added new

}

}

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

Zend ajax jquery extjs json xml ajaxcontext

March 2, 2010 Leave a comment

How to zend ajax?

1. application/controllers/IndexController.php:

<?php

class IndexController extends Zend_Controller_Action

{

public function init()

{

$ajaxContext = $this->_helper->getHelper(‘AjaxContext’);

// make a file application/views/scripts/index/list.ajax.phtml

// allowing list.ajax.phtml to be viewed by ajax query.

$ajaxContext->addActionContext(‘list’, ‘html’)

->initContext();

}

// using the AjaxContext

public function listAction(){

echo ‘2. application/controllers/IndexController.php > IndexController > listAction() > Its me pal!’;

}

public function indexAction()

{

}

public function addAction()

{

}

public function editAction()

{

}

public function delAction()

{

}

}

Read more…

Zend router Zend route

March 1, 2010 Leave a comment

How to zend route?

1. application/Bootstrap.php > initialize

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

	/**
	 * @Step 1
	 * 
	 * 
	 */
    public function _initRoutes()
    {

		/**
		 * @Step 2
		 * if not, i have blank view/action.
		 * 
		 */    	
    	echo '[important] - did i got initialized? yes Bootstrap.php > public function _initRoutes(){  }';	
        $front = Zend_Controller_Front::getInstance();
	    $router = $front->getRouter();

		/**
		 * @Step 3
		 * 
		 */
        $route = new Zend_Controller_Router_Route(
          /**
           * @Search input url
           *  
           * url: http://localhost/myzf/public/add/--------anything-----that----sucks-----
           * or   http://localhost/add/.....anything....that----sucks..
           * 
           */
          'add/:add:',

          array(
          	/**
          	 * @Route TO?:
          	 * 
          	 * a. application/controllers/IndexController.php 
          	 */
              'controller' => 'index',

			/**
			 * @Execute WHAT?:
			 * 
			 * a. application/controllers/IndexController.php
			 * b. public function addAction(){ -- run mee -- }
			 * 
			 */	
              'action'     => 'add'

          )
        );

        $router->addRoute('add', $route);

    }
    	
}

 Read more...
Categories: centOS, Fedora 12, PHP, Unix/Linux, Zend