Showing posts with label zend. Show all posts
Showing posts with label zend. Show all posts

Tuesday, December 18, 2012

Zend framework 2 and firebug and composer

To install firebug core lib via composer onto zend framework 2,

vendor/composer.json

#add:
 "firephp/firephp-core": "dev-master"

#example:

"require": {
        "php": ">=5.3.3",
        "zendframework/zendframework": "2.*",
        "firephp/firephp-core": "dev-master"
    }

#run in console:
php composer.phar install

#for update on existing library
php composer.phar update

Wednesday, August 1, 2012

jQuery form and Zend_Form File

It appears that Zend Form will validate fail if we are using ajax or jquery form to submit the form.
To fix the issue, just ensure the form is submitted with the parameter: iframe: true

Also note that IE 8 or below will behave strangely when submitting via jQuery Form with file input.
So avoid using it on IE8 or below...

Thursday, May 17, 2012

infinite loop in bootstrap module

It seems that if you want to develop a bootstrap for module,
you will need to extends Zend_Application_Module_Bootstrap

But how to get Layout from bootstrap_bootstrap?
$this->getApplication()->getResource("layout");

How to get view?
$this->getApplication()->getResource("layout")->getView();

What if i get undefined getView of a undefined object?
Yes, this problem is because layout and view bootstrap is not loaded in Zend_Application_Bootstrap_Bootstrap.

Makesure to run these in the class which extends bootstrap_bootstrap:
$this->bootstrap("View");
$this->bootstrap("layout");


Tuesday, May 15, 2012

Zend DB Select join

Example of joining table using dbtable (EntStudio_Db_Table_Abstract)

$maintable = "x";

$query = $dbtable->select();
$query->setIntegrityCheck(false);
$query->from($dbtable, array("*")); //only specify column for main table

   
$query->join(array("u" => "table2"),  $maintable . ".userid=u.id", array("username")); //only specify column for table2

to output to test:
echo $query;

to get results:

$resultSet = $dbtable->fetchAll($query);
$entries   = array();
foreach ($resultSet as $row) {
//... codes here
}


to get a single row:
$row = $dbtable->fetchRow($query);

Zend Notification

Zend built in notification are divided into session saved message, and current message.
$flashmsg = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');

To get last added message in previous request (which is saved in the session):
$flashmsg->hasMessages();
$aMsg = $flashmsg->getMessages();

To clear the messages storage:
$flashmsg->clearMessages();
--------------------
To get current added message (same request):

$flashmsg->hasCurrentMessages();
$aMsg = $flashmsg->getCurrentMessages();

To clear the current messages storage:
$flashmsg->clearCurrentMessages();


Please note that the current and the session message are separated, and need to be called respectively to retrieve all messages in the notification

zend view render vs layout render

To render another view file within the same controller,
$view / $this->render("filename.phtml");

to render a view file within layout:
$view / $this->layout()->render("filename"); //without .phtml