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

Thursday, February 13, 2014

How to Add 3rd Party Libraries to Zend Framework 2

You can easily add other libraries to Zend Framework 2 whether they are your custom libraries, 3rd party libraries or standard packages from packagist.org or Github.  However, the explanation and method on how to add and autoload them properly to the software architecture was not easy find, at least for me.

Since you're here, I've made it a tad easier for you and itemised the use-cases.

1) Adding custom libraries which are GLOBAL to your application 

 Edit composer.json and add within the closure,

    "autoload": {
        "psr-0":  {"MyLibrary\\":"vendor/my/library/path"}
    }

Then run "composer update" from the CLI under your application root directory. This will add an entry to your <APPLICATION_PATH>/vendor/composer/autoload_namespaces.php.

Alternatively, you can directly add an entry to it.

return array(
    'Zend\\' => array($vendorDir . '/zendframework/zendframework/library'),
    'MyLibrary\\' => array($vendorDir . '/my/library/path'),
);

Monday, January 27, 2014

How to Make Your Module Default in Zend Framework 2

Just make sure you have the proper route to slash (/) and the first in the alphabetical hierarchy of the other modules.

/module/modulename/config/module.config.php

'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/', 
                    'defaults' => array(
                        'controller' => 'Account\Controller\Index',
                        'action'     => 'index',
                    ),
                ),
            ),
    ),
);

Friday, January 24, 2014

How To Set-up ZendFramework 2 for Developers from Scratch

Here are a few easy steps to bootstrap your development using Zend Framework 2.x. This assumes that you are using PHP 5.3.x or higher on a *nix machine. Was tested to work on Fedora and CentOS.

1) Install composer

(make sure you are a root user)
# sudo -i
# curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/src/
# mv /usr/local/src/composer.phar /usr/local/bin/composer

# chmod +x /usr/local/bin/composer

2) Download and install ZendFramework Skeletion Application

# composer create-project --repository-url="http://packages.zendframework.com" zendframework/skeleton-application /path/to/install/skeleton/app dev-master

Saturday, October 19, 2013

How To Redirect From the Bootstrap in Zend Framework 1x

If you need to redirect from the Bootrstrap context, you can do:


$front = Zend_Controller_Front::getInstance();
$response = new Zend_Controller_Response_Http();
$response->setRedirect(Zend_Registry::get('config')->et->core->url . '/' . $args[1]);
$front->setResponse($response);


The most simplistic, basic PHP approach would be:

 header("Location: " . Zend_Registry::get('config')->et->core->url . '/' . $args[1]);
ob_end_clean();
ob_end_flush();

Note: The ob_* functions are to terminate the output buffering routine of Zend Framework and start sending headers to the browser.

Or,


 header("Location: " . Zend_Registry::get('config')->et->core->url . '/' . $args[1]);
exit;

Note:  the "exit" will force Zend Framework to reach the EOF (end of file) and thus start sending the headers to the browser.

Whichever method you choose would work. Re: their advantages, convention-wise the first one is the most ideal, the fastest however would be the last.



Sunday, April 8, 2012

Fatal error: Class 'Model_XXXX' not found in Zend Framework

You're here because you have the same problem as I had and you kept on seeing that error several times. The problem here is not really a problem but rather you have a namespace set for your application inherited by how your models are being loaded. If you used the ZFTool it is more than likely that the namespace is the default which is "Application". In order for the usual or earliest form of ZF model initialization to work, you need to eliminate the namespace.

Sunday, April 1, 2012

PEAR to install Zend Framework

Probably the easiest way to install Zend Framework on your system is to use PEAR to install and upgrade the framework. Note that the below instructions assume that you have PEAR installed in your system. The commands have been tested in Linux OS CentOS/RHEL.

Installation

#  pear channel-discover zend.googlecode.com/svn
pear install zend/zend

Upgrade

# pear upgrade zend/zend

The resource information came from Zend Framework PEAR repository.

Sunday, April 3, 2011

Disable Zend_Layout and Zend_View

Disabling Zend Layout

$layout = Zend_Layout::getMvcInstance();
if ($layout) {
    $layout->disableLayout();
}

Prevent Zend_View From Rendering in the Current Action / State

$this->_helper->viewRenderer->setNoRender();
Note: Put the above code post-bootstrap of the front-controller. Meaning you should put them through a Controller Plugin or [your_zend_controller]::init() or [your_zend_controller]::preDispatch() methods. This is because at the bootstrap level, the layout and views objects are still out of scope or not yet instantiated. They become available after the routerShutdown() method of the front controller.

 What do you use them for?

Monday, March 14, 2011

Nasty Zend Framework Module BootStrapping Issue Solved

You have been building individual mini-applications based on Zend Framework and then finally it's time to integrate them with the rest of your gargantuan application. You are happy that you were able to develop them individually by using the modular architecture of Zend Framework by a simple "drop" and "bootstrap" methodology. And then, you encounter this nasty fatal error.
Fatal error: Maximum function nesting level of '100' reached, aborting

Wednesday, July 7, 2010

Zend Framework, and Mongo DB - Seamless Integration

I decided to create a Zend Framework compatible PHP class library that can do the following:

1. Easily integrate the PHP drivers to Zend Framework