EzDevInfo.com

zend-framework2 interview questions

Top zend-framework2 frequently asked interview questions

You must enable the openssl extension to download files via https

I wanted to install Zend Framework 2. So I downloaded the skeleton application. As mentioned in the ZF2 manual, we have to issue the command

php composer.phar install 

Inside the skeleton.

But I'm getting an error

You must enable the openssl extension to download files via https

Then I enabled the ssl_module in my wamp, I checked the php_ini file and I can see the following line

extension=php_openssl.dll

Still I'm getting the same error. Anybody having any clue what I missed out?


Source: (StackOverflow)

Zend Framework 2 for a Zend Framework Newbie [closed]

I'd like to use ZF2 for an upcoming project. However, I find it really hard to understand the few tutorials that I've found out there. Most of them just tell you to put stuff in files without really explaining what everything is or any other option I may have.

Is there any book or tutorial for an absolute zf beginner?


Well, I started using Yii until ZF2 is released.

Yii has just amazed me. In two days I've been able to start building something. It is dead simple, yet powerful. They have great documentation and the framework is very easy to understand and use if you have a good knowledge of MVC and SQL. The documentation on their site is also very good. There are tutorials for absolute beginners. That I liked. Zend may be a more robust and powerful framework, but it's tediously painful to learn. It lacks the simplicity of Yii. I went nuts trying to understand all those configuration lines.

I followed every tutorial recommended in this thread for two weeks and gave up. Telling someone to just enter some code without explaining what it means or how it can be tweaked is not a good way to teach and promote a framework. I'll pick up ZF2 when it's released. I hope they make it friendlier. I hope the documentation also improves and goes from simple to complex examples. I really want to learn the ZF.


Source: (StackOverflow)

Advertisements

Change layout in the controller of Zend Framework 2.0

I am learning ZF2.0 beta. In ZF1 we can change layout on the fly in controller:

Zend_Layout::getMvcInstance()->setLayout('layoutname');

But in ZF2.0 Zend\Layout class doesn't has method getMvcInstance(). I think that it can be made using dependency injections but not sure.


Source: (StackOverflow)

ZF2 unit-testing authentication

I was learning about unit testing and I attempted to resolve the following issue:

Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for zfcUserAuthentication

... using the only answer given at:

Simple ZF2 Unit Tests for a controller using ZfcUser

So my setUp function looks the same. Unfortunately, I get the error message:

Zend\Mvc\Exception\InvalidPluginException: Plugin of type Mock_ZfcUserAuthentication_868bf824 is invalid; must implement Zend\Mvc\Controller\Plugin\PluginInterface

It is caused at this part of the code (split up in my code in the same way):

$this -> controller->getPluginManager()
->setService('zfcUserAuthentication', $authMock); // Error refers to this line.

The $authMock object is apparently not implementing plugininterface, which I need to implement to pass into setService.

Is $authMock not meant to be passed there for it's use in unit testing? Should I be using a different (unit-testing oriented) setService method?

I need a way to handle logging into my application, or my unit testing is pointless.

Thanks for any advice.

=== Edit (11/02/2013) ===

I wanted to focus on this part for clarification, as I think this is the problem area:

// Getting mock of authentication object, which is used as a plugin.
$authMock = $this->getMock('ZfcUser\Controller\Plugin\ZfcUserAuthentication');

// Some expectations of the authentication service.
$authMock   -> expects($this->any())
    -> method('hasIdentity')
    -> will($this->returnValue(true));  

$authMock   -> expects($this->any())
    -> method('getIdentity')
    -> will($this->returnValue($ZfcUserMock));

// At this point, PluginManager disallows mock being assigned as plugin because 
// it will not implement plugin interface, as mentioned.
$this -> controller->getPluginManager()
->setService('zfcUserAuthentication', $authMock);

If the mock doesn't handle necessary implementations, how else am I to pretend to login?


Source: (StackOverflow)

Zend Framework 1 vs Zend Framework 2 performance [closed]

Zend Framework 2 was just released and Zend offers support for ZF1 for only 18 months from now. I know they were working for new features in ZF2 and then they were going to do some major speed improvements to it since it was 5 times slower than ZF1.

I would like to know how slower is ZF2 than ZF1 from benchmarks or tests you did and not pure speculation.

The latest benchmark I found is from February 22, 2012 and it concludes that ZF2 is 4 times slower than ZF1.

Link here


Source: (StackOverflow)

Zend Framework 2 + Doctrine 2 [closed]

I would like to start developing with Zend Framework and I would like to use zf2. Since I use Doctrine 2, can you suggest some tutorials to help me to integrate it in zf2? Thanks!


Source: (StackOverflow)

Step by step migration from Zend Framework 1 to 2

I have to migrate an application from Zend Framework 1.12.0 to version 2. There seem to be no migration guides yet. I have already studied ZF2 coding conventions and I adopted dependency injection (Zend\Di) and PHP 5.3 namespaces. My goal is to refactor my ZF1 application into a ZF2 module.

Question: Is it possible to proceed step-by-step with an at least partly working application after every step and avoid huge refactoring steps? If yes, what are the steps?

Here's my idea of such a step-by-step migration, but I don't know if I end up with a working application after every step:

  1. Start by setting up the ZF2 Skeleton Application
  2. Set up a new module (MyApp) and reorganize the contents of my ZF1 application into the MyApp module folder structure. Then set up very basic configuration and bootstrapping and migrate the IndexController by extending it from the ZF2 AbstractActionController. The models (Zend_Db) and views (Zend_View) will be migrated later. The goal here is to have a working IndexController::indexAction which doesn't have many dependencies.
  3. Set up more configuration and bootstrapping (Routing, Translate, Locale, Cache, Db, Acl, ViewHelpers, ...). I'd like to set up the ZF1 versions of these components first and migrate them later one by one.
  4. Migrate the other controllers and set up dependency injection into the controllers either with Zend\Di or by using the ServiceManager.
  5. Set up automatic deployment by making the old phing scripts work with the new directory structure.
  6. Migrate the views (including helpers) and forms to ZF2.
  7. Migrate the models (from Zend_Db either to ZF2 Zend\Db or to Doctrine).
  8. Migrate other ZF1 components one by one (Translate, Locale, Cache, Acl, ...).
  9. Refactoring rehab and long holiday.

However, I will have a workin application after every step only if certain ZF2 components work together with ZF1 components. I have no idea if it's e.g. possible to use ZF1 views (and view helpers) with ZF2 controllers.


Source: (StackOverflow)

ZF2: Get url parameters in controller

I have experienced Zend Framework 1 and I've build some apps with that framework.

Now, I'm experimenting Zend Framework 2, but I'm stuck on the url parameters. I've setup my routing like this:

// Setup for router and routes
'Zend\Mvc\Router\RouteStack' => array(
    'parameters' => array(
        'routes' => array(
            'default' => array(
                'type'    => 'Zend\Mvc\Router\Http\Segment',
                'options' => array(
                    'route'    => '/[:slug]',
                    'constraints' => array(
                    'slug' => '[a-zA-Z][a-zA-Z0-9_\/-]*'
                    ),
                'defaults' => array(
                    'controller' => 'Htmlsite\Controller\BootController',
                    'action'     => 'index',
                    'slug' => 'home'
                    ),
                ),
            ),
        'home' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Htmlsite\Controller\BootController',
                    'action'     => 'index',
                    ),
                ),
            ),
        ),
    ),
),

As you can see, I've tried to make a variable slug. How can I access this variable?


Source: (StackOverflow)

configure multiple databases in zf2

How can I configure (and use) multiple databases in Zend Framework 2? Currently I have this in my global.php:

return array(
    'db' => array(
        'driver'         => 'Pdo',
        'dsn'            => 'mysql:dbname=my_db;host=localhost',
        'driver_options' => array(
            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
        ),
        'username' => 'user',
        'password' => '******',
    ),
    'service_manager' => array(
        'factories' => array(
            'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
        ),
    ),
);

But I do not see a way to add a second one.


Source: (StackOverflow)

Zend Framework 2 - Layout and variable

i have a layout used by all my views and i need to assign a variable from a controller to this layout , if i use this method on a controller it doesn't work :

public function indexAction()
{
    return new ViewModel( array(
        'testvar' => 'bla',
    ));
}

anyone can help me ?

thanks


Source: (StackOverflow)

How to use Zend\Session in zf2?

Does anybody try zf2? I can not understand new mechanism of using sessions in zf2. How can I write and read to/from the session in new zend framework?

Also I can not find any examples in the internet.


Source: (StackOverflow)

Using dgrid in form collections in a Zend Framework 2 application

For our new project, we have started using Zend Framework 2 and Dojo 1.8. ZF2 has a completely rewritten form module, which now features the new CollectionElement for one-to-many relationships. Regarding UI I find, that dgrid fits best for such relationships (using the editor column plugin), so I started extending FormCollection, FormRow and FormElement view helpers, so they can render the desired dgrid. Everything was fine until I realized, that I cannot set per-row input names for the dgrid widgets.

I started with the ZF2 documentation rearding form collections. One can see, that collection input elements have array-like names like

order[products][0][name]
order[products][0][price]
order[products][1][name]
order[products][1][price]

On the other hand, dgrid's configuration is column based, so I can have a column definition like

editor({
    field: "_dojo_textbox_505ee3a390d705_26717315", 
    label: "Name",
    editorArgs: {
        name: "order[products][{index}][name]",
    }
}, TextBox)

This column definition will define set the same widget name for all rows, which does not work with the ZF2 collection data format requirement.

What I also tried is naming the column like this:

order[products][]

which works, but does not allow the desired format

order[products][][name]

Maybe there is a way to post the data like this:

order[products][name][]

and have it converted afterwards, but the solution doesn't looks right. Beside this I am trying to produce reusable code and want to avoid per-form data modifications.

Since I am trying very hard to avoid onSubmit/onClick event handling for data conversion, there are 2 possible solutions: 1. Make dgrid able to set per-row widget names 2. Make ZF2 form understand some other-than-standard POST format for collections

Unfortunately I ran out of ideas, how either of those solutions can be done, so I will be most thankful, if you can give me a hand with this!

Since this is somewhat related with my current question, I will place it here as a side question: What other than this UI solution do you use for your one-to-many form interfaces with dojo?


Source: (StackOverflow)

How to access route, post, get etc. parameters in Zend Framework 2

How can I get various parameters related to the page request in zf2? Like post/get parameters, the route being accessed, headers sent and files uploaded.


Source: (StackOverflow)

How can you add query parameters in the ZF2 url view helper

I'm attempting to create a url with a query string using a route, like so:

$this->url('users') -> /users
$this->url('users', ['sort' => 'desc']) -> /users?sort=desc

However this doesn't seem to work (the second helper actually outputs /users). According to this unofficial, out-of-date documentation there was once a way to do this by appending /query to the route name, however this gives a route-not-found exception.

Can this be done using the current url helper?


Source: (StackOverflow)

How to best select a PHP framework - Laravel, Symfony, Zend, Etc [closed]

My company wants to adopt a PHP framework and I am being asked to decide which one to use going forward.

Our requirements are simple

  1. It must be part of the php-fig
  2. Must look like it will be around & active for at least another 10 years
  3. Must have a healthy community
  4. Must have libraries/bundles/modules/packages/etc or whatever they are called that we can draw on to speed up development.

Using the above criteria I have found frameworks that I like

  • Symfony -> Seems to be an industry leader / feels a little over engineered
  • Laravel -> very popular at the moment and easy to use/understand
  • Zend -> Zend 1 hurt my feelings and I have never really forgiven it, I am just not comfortable with Zend

I would like to use Laravel but point 2 above concerns me as its really driven by one person, even though there is s strong community, that one person still has too strong an influence its not like Drupal where if Dries goes away the community will not crumble, I feel that if Tyler goes then Laravel will fall. And as much as I like it I don't want to tie my company to that wagon.

This question is NOT about which framework is better BUT how to best decide on selecting a framework for your Company


Source: (StackOverflow)