Zend mail
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();
Zend zend_layout
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; ?>
Zend zend_view
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);
Zend Registry global
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’);
Zend zend_db sql mysql
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’
));
Zend get post request
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’));
}
}
Zend debug
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
}
Zend sessions
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
}
}
Zend ajax jquery extjs json xml ajaxcontext
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()
{
}
}
Zend router Zend route
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...