Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3674026
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:48:18+00:00 2026-05-19T02:48:18+00:00

I have created a Zend Framework website and I’m now updating it to switch

  • 0

I have created a Zend Framework website and I’m now updating it to switch out the layout file depending on whether or not the user is on a mobile device.

I have written a class to deal with the detection but I don’t know where is best to place this check and also trigger the layout file being used.

Code:

include(APPLICATION_PATH . "/classes/MobileDetection.php");
$detect = new MobileDetect();

if ($detect->isMobile()) {
    $layout = $layout->setLayout('mobile');
} 

I can trigger the layout from the Bootstrap function _initViewHelpers() but I get a 500 error as soon as I add the include line above.

Any recommendation on how and where to place this? I originally has a helper that dealt with the check but that was used in the layout itself rather than enabling me to swap the whole layout file out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:48:18+00:00Added an answer on May 19, 2026 at 2:48 am

    You can use a plugin, that’s what I do:

    <?php
    
    class Mobile_Layout_Controller_Plugin_Layout extends Zend_Layout_Controller_Plugin_Layout
    {
    
        public function preDispatch(Zend_Controller_Request_Abstract $request)
        {
            switch ($request->getModuleName()) {
                case 'mobile': $this->_moduleChange('mobile');
            }
        }
    
        protected function _moduleChange($moduleName) {
            $this->getLayout()->setLayoutPath(
                dirname(dirname(
                    $this->getLayout()->getLayoutPath()
                ))
                . DIRECTORY_SEPARATOR . 'layouts/scripts/' . $moduleName
            );
            $this->getLayout()->setLayout($moduleName);
        }
    
    }
    

    I keep it in library/ProjectName/Layout/Controller/Plugin/Layout.php.

    In your Bootsrap, you will need to incorporate something like this:

    Zend_Layout::startMvc(
        array(
            'layoutPath' => self::$root . '/application/views/layouts/scripts',
            'layout' => 'layout',
            'pluginClass' => 'Mobile_Layout_Controller_Plugin_Layout'
        )
    );
    

    It actually took me a while to get this figured out, but once you work through it, you will be so much happier. Hope that helped 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm starting out using the Zend Framework and have created a suitable model which
I have created a login page at www.mywebsite.com/members/login I'm using Zend Framework, Now I
I am running Zend Framework 1.11.10 on Ubuntu 11.10. I have created 3 modules
All, I have a PHP website written in Zend Framework and MVC. Most of
I have a social networking website built upon the zend framework. My application also
I have a website built on Zend Framework. I want to run the site
I am using Zend Framework v 1.10 I have created a custom function in
I am busy with a new project based on zend framework. I have created
I have my website in /var/www/invent. I have zend-framework in /var/www/invent/library. Basically what i
Good day to all. I have a site (created with zend framework and smarty)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.