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 9219143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:02:15+00:00 2026-06-18T03:02:15+00:00

I would like Zend Studio to recognize the class type for all the controller’s

  • 0

I would like Zend Studio to recognize the class type for all the controller’s models, in a CakePHP 2.x project.

This is how I currently do it.

class MyController extends AppController
{
      public $uses = array('Scan');

      public function index()
      {
          /* @var $scan Scan */
          $scan = $this->Scan;
          // do stuff...
      }
}

The above works fine, and Zend will refactor all references to the Scan class correctly, but this is a pain because it has to be done in every action.

I’d like to do this instead.

class MyController extends AppController
{
      public $uses = array('Scan');

      /** @var Scan */
      public $Scan;

      public function index()
      {
          // do stuff...
          $this->Scan->.....
      }
}

When I tried to declare it as a property then $this->Scan is null, and Cake isn’t loading the model.

Is there a way to declare it as a property with a phpDoc type without breaking CakePHP?

  • 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-06-18T03:02:16+00:00Added an answer on June 18, 2026 at 3:02 am

    CakePHP will automatically attach this varialbe to your Controller and what you’re essentially doing is redeclaring it.

    I am not completely shure how this is done internally in Cake but have you tried declaring $Scan before $uses?
    Another way would be to redeclare the Controller’s constructor to hadnle this but that seems a bit too far-fetched.

    Total refactoring capability is something we’re still waiting for and it will come with total adoptance of the PSR standards and especially namespaces.

    Edit:
    Here’s a nifty (hack) way to add autoComplete for Helpers in Views. This will work for CakePHP >= 2 and only in Views. Also I’ve used this only in Eclipse but I suppose it should work in any IDE since it is OOP and PHPDoc based.

    “All you need to do: is to create a file called “ThisHelper.php” in the app/View directory (not in View/Helper) with the following contents:

    App::uses('AppHelper', 'Helper');
    /**
     * this Helper
     *
     * @property Html $Html
     * @property Session $Session
     * @property Form $Form
     */
    class this extends AppHelper
    {
        var $Html;
        var $Session;
        var $Form;
    
        public function __contruct()
        {
            $this->Html = new HtmlHelper($View);
            $this->Session = new SessionHelper($View);        
            $this->Form = new FormHelper($View);        
        }
    }
    
    $this = new this();
    

    To add support for other helpers (Cake core or not) just add them as variables to this class, for example if you want to add PaginatorHelper do:

    @property Paginator $Paginator
    ....
    var $Paginator;
    .....
    public function __contruct()
    {
        .............
        $this->Paginator = new PaginatorHelper($View);
    }
    

    Probably the best thing to do is to add properties for all CoreHelpers available in CakePHP.
    Of course it will work with any custom Helpers if you add them. You do not need to include this file in any PHP Script – just add it to the app/View/ directory.

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

Sidebar

Related Questions

I would like to know if this method of setting up routing in Zend
I would like to set up a Zend Framework project in a subdirectory: /public_html
I would like to translate this MySQL query to the Zend format: SELECT count_panne,
I've started using Zend Framework and Studio for my projects and would like to
I would like to enjoy code formatting for .json files in Zend Studio. I
I'm building my first Zend/Doctrine project and would like to be able to access
I am playing with Zend 1.9 and would like to have the language parameter
I'm building a Zend Framework 1.11.11 application and would like to make the routes
I'm new to Zend Framework. I would like to know how to implement zend
I'd like to do a Zend db update with an OR clause. What would

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.