Deprecated stuff in CakePHP 1.2

Published on January 10, 2008 and tagged with cakephp  deprecated

Yesterday I got asked by Beth in a comment whether there is a list of deprecated stuff. As I am not aware of such a list I compiled one by searching for the term “deprecated” in the cake folder of CakePHP 1.2beta. You find the results below. Most of the deprecated stuff still works, but some of it will show you a notice when used during development (when debug > 0). It is recommended to no longer use the deprecated stuff, as it is possible it will be removed in future releases. Ok, here we go:

On the console the command

cake acl initdb

has been replaced by

cake schema run create DbAcl

In basics.php all load functions have been replaced by App::import(): loadView(), loadModel(), loadController(), loadHelper(), loadPluginHelper(), loadComponent(), loadPluginComponent(), loadBehavior(), loadModels(), loadPluginModels(), and loadControllers().

The function listClasses() has been replaced by Configure::listObjects(), and the implementations of setUri() and setUrl() have been moved to the dispacher and are now called uri() resp. getUrl().

The initialization of the cookie component has changed, it should be configured in the beforeFilter of the controller and therefore the initialize() method should no longer be used.

The implementation of cleanUpFields() has been moved from the controller to Model::deconstruct().

In the model two methods are deprecated: loadInfo() has been replaced by Model::schema() and generateList() by Model::find(‘list’). Also the parameter usage of validates() and invalidFields() has been deprecated, you have to set the $data property instead.

In the form helper the method submitImage() should no longer be used, instead the submit() method can be used.

As there is the form helper for creating form elements, all form-related methods in the HTML helper are deprecated: radio(), password(), textarea(), checkbox(), hidden(), input(), tagValue(), validate(), validateErrors(), and tagErrorMsg().

In the Javascript helper the $safe parameter for the codeBlock() method, plus the parameters $prefix, $postfix, $stringKeys, $quoteKeys, and $q for object() are deprecated.

In the helper class the method setFormTag() has been replaced by setEntity().

The properties $themeElement, $themeLayout, and $themePath are no longer needed in the theme class.

In the file class many methods have been renamed, and therefore the old names are deprecated: getFullPath(), getName(), fileName(), getExt(), getMd5(), getSize(), getOwner(), getGroup(), getChmod(), and getFolder().

The functionality of chmodr() and mkdirr() from the folder class is now handled by chmod() resp. mkdir().

In the router the routes for web services are deprecated: “/rest/”, “/rss/”, “/soap/”, “/xml/”, and “/xmlrpc/”. The same is true for the routes “/bare/” and “/ajax/”.

Last, but not least, the validation constants VALID_NOT_EMPTY, VALID_NUMBER, VALID_EMAIL, and VALID_YEAR are deprecated.

55 comments baked

  • Beth January 11, 2008 at 02:23

    You’re the MAN!!!

    Thanks so much for taking the time collecting and posting this. It goes a long way in helping us mere mortals :)

  • phpsc January 13, 2008 at 16:38

    Found this Deprecated List from API http://api.cakephp.org/1.2/deprecated.html

  • cakebaker January 16, 2008 at 12:22

    @Beth, phpsc: Thanks for your comments!

    @phpsc: Thanks for the link, I wasn’t aware there exists such a page in the API.

  • speedmax January 17, 2008 at 02:30

    Model::generateList() deprecated, use Model::find(‘list’)

    r6360 commit introduced a way to do custom fields

    Model::find(‘list’, array(‘fields’ => array(‘Model.id’, ‘Model.custom_name’))

    Now that is beautiful API

  • cakebaker January 18, 2008 at 17:52

    @speedmax: Yes, it is nice, even though it is probably more difficult to use it (without documentation).

  • Pensae.com | Fungsi yang tak lagi berfungi di CakePHP 1.2 January 27, 2008 at 17:55

    [...] lainnya, setelah browsing sana-sini akhirnya ketemu juga dengan daftar deprecated stuff di blognya CakeBaker, jika anda sedang belajar CakePHP 1.2 mungkin daftar ini bisa jadi pertimbangan, soalnya beberapa [...]

  • Promet CakePHP» Blog Archive » CakePHP 1.2 January 31, 2008 at 03:05

    [...] with the new functionalities are the deprecated ones. Check out the Deprecated Stuff in CakePHP 1.2 for a list of the deprecated items. Although these stuffs still work, they are not recommended for [...]

  • Matt Huggins February 08, 2008 at 02:58

    I might be missing something, but the new method for generating lists is not as good. My issue is that, previously with generateList, both the ID and display name could be specified. Now in 1.2, only the display name can be specified, and the primary key is assumed as the ID. I looked through the model.php code as well, and it looks like there’s no value that can be passed in to overwrite this.

    If anyone sees a solution for this, I would be very grateful for your help!

  • Matt Huggins February 08, 2008 at 02:59

    Oops, I missed speedmax’s response. That should solve my problems, I’ll check it out!

  • JDS February 09, 2008 at 18:55

    Thank you. Your blog kicks ass.

  • CakePHP Tutorials :: PseudoCoder.com February 11, 2008 at 06:28

    [...] cakebaker.42dh.com – Deprecated stuff in CakePHP 1.2 [...]

  • cakebaker February 11, 2008 at 18:26

    @JDS: Thanks!

  • marcin March 08, 2008 at 00:15

    i’ve try
    Model::find(’list’, array(’fields’ => array(’Model.id’, ‘Model.custom_name’))

    but it returned array (‘id’='id’) instead (‘id’=>’custom_name’)

    :(

  • cakebaker March 09, 2008 at 18:15

    @marcin: Hm, which CakePHP version do you use?

  • KireZ March 26, 2008 at 14:06

    i should convert $this->Company->generateList() to $this->Company->find(‘list’); for 1.2 as generateList is depricated. But how can i convert $this->Company->generateList(null,null,null,null,’{n}.Company.company_name’); ?

  • cakebaker March 27, 2008 at 08:09

    @KireZ: Something like

    $this->Company->find('list', array('fields' => array('Company.company_name')));
    

    should do the trick.

    Hope that helps!

  • yunhaihuang April 02, 2008 at 04:37

    how can i convert this:
    $this->set(‘Cat_List’,$this->Ad->Cat->generateList(null, ‘name_de ASC’, null, ‘{n}.Cat.id’, ‘{n}.Cat.name_de’));

  • yunhaihuang April 02, 2008 at 04:40

    if i convert it as below:
    $this->set(‘Cat_List’,$this->Ad->Cat->find(‘list’,array(‘order’=>’name_de ASC’,'fields’=>array(‘{n}.Cat.id’,'{n}.Cat.name_de’)))));
    it only returned me:
    array (’id’=’id’) instead (’id’=>’name_de’)

  • cakebaker April 02, 2008 at 17:40

    @yunhaihuang: Hm, your example with find causes an error here (I’m using the latest version from the repository). If I remove the “{n}” from the fields array, then I get id/name_de pairs as result.

    Hope that helps!

  • Pablo Pedrosa April 03, 2008 at 12:02

    Thanks a lot for the information, I have to migrate from 1.1 to 1.2, and this information will be VERY usefull. Thx!!!!!

  • cakebaker April 03, 2008 at 16:06

    @Pablo: Good luck with your migration!

  • yunhaihuang April 04, 2008 at 03:30

    Thanks for your help! But it’s work as i expect, althought i remove the ‘{n}’(i’m using cakephp beta). with best wishes!

  • yunhaihuang April 05, 2008 at 04:06

    i’m sorry about my mistake.
    it doesn’t work as i expect, althought i removed the ‘{n}’.
    please help me overcome this error.

  • yunhaihuang April 05, 2008 at 04:07

    i’m sorry about my mistake.
    it doesn’t work as i expect, althought i removed the ‘{n}’.
    please help me overcome this situation.

  • cakebaker April 07, 2008 at 17:27

    @yunhaihuang: What doesn’t work? Can you give an example of what you try and what you expect?

  • yunhaihuang April 12, 2008 at 12:02

    i want it return a list (cat.id/cat.name_de), but it only return me a list with cat.id

  • cakebaker April 13, 2008 at 19:05

    @yunhaihuang: Set debug to 2 (in app/config/core.php) and look what SQL code cake generates. Maybe you can then figure out what’s going wrong…

    If not, which cake version do you use?

  • Pravin Gundawar May 15, 2008 at 09:04

    Hi Everyone,
    You can do like this
    $this->Ad->Cat->displayField = ‘name_de’;
    $this->set(’Cat_List’,$this->Ad->Cat->find(’list’));

  • cakebaker May 15, 2008 at 10:51

    @Pravin: Thanks for your hint!

  • MD. Nur Hossain May 20, 2008 at 09:50

    @Pravin: Thankz for nice info!

  • Linda DeBoer May 22, 2008 at 15:57

    @Pravin: Thanks for very much!

    I read alot about setting the displayName but nothing about being able
    to set it “on the fly” in the controller. That little bit of info was sooooo missing for me. :-)

  • josepzin June 05, 2008 at 09:37

    I have the same problem, i solved with:
    $this->Cat->displayField = ‘name_de’;

    It can be used too in model cat.php:
    var $displayField = ‘name_de’;

    Uf… before, we make “generaleList” and go! now is more work :P

  • josepzin June 05, 2008 at 09:41

    If we use in the BD definition ‘title’ or ‘name’, then it work ok.

  • cakebaker June 07, 2008 at 16:01

    @josepzin: Thanks for your explanations!

  • olivier July 22, 2008 at 01:54

    Hi!
    Trying to use the Ckae 1.2′s “find” functions, and having an hard time! My problem is the following:
    i’d like to fetch data from a table. What idon’t know is the form of data “find” returns.
    A sample of my code :
    $entry = $this->SearchWord->find(‘list’, array(‘conditions’ => array(‘SearchWord.word_text’ => $tempWord) , ‘fields’ => array(‘SearchWord.id’, ‘SearchWord.word_text’)));

    $matchToSave['search_word_id'] = $entry['id'];

    at execution time, i have the following error :

    Notice (8): Undefined index: id [APP\controllers\users_controller.php, line 753]

    Any idea?

    Thanks a lot!

  • cakebaker July 22, 2008 at 17:23

    @olivier: Add a debug($entry); statement and you will see why you get that error ;-)

  • olivier July 22, 2008 at 17:27

    Will try it out tonite. Thanks !!

  • olivier July 23, 2008 at 10:46

    Thank you for the tip cakebaker. the $debug output helped me use the find() return efficiently

  • olivier July 23, 2008 at 10:51

    A question on the form helpers in Cake1.2:
    it seems that specifying a size for a text area (or any other form element) has absolutely no effect on the look of the element. The size cannot be changed and the default size is just inappropriate (too large).

    How can one set the form elements’ size and expect a result with Cake1.2?

  • cakebaker July 23, 2008 at 17:44

    @olivier: Cool to hear it was helpful for you :)

    And regarding your question, you can set all HTML attributes by using the $options parameter of the respective method. For example:

    $form->input('Model.field', array('size' => 100));
    

    Hope that helps!

  • olivier July 23, 2008 at 17:49

    I think i’ve tried that already. Will try again tonite and tell you the result. Thank you

  • olivier July 25, 2008 at 01:29

    Hello, I tried (again) to specify the length of the form field. And it doesn’t seem to change. Even if I go from 5 to 100. The field lenght remains unchanged. Have you successfully tried to set a form’s size with Cake 1.2?

  • cakebaker July 25, 2008 at 16:40

    @olivier: Yes, it works fine here (with the latest version of cake 1.2 from the repository). Maybe you have defined a size for “input” in your CSS file? Then the size attribute of the input tag is ignored. Also have a look at the generated HTML code, is it correct?

    Hope that helps!

  • Stinkbug.net » Blog Archive » Migrating from CakePHP 1.1 to 1.2 August 04, 2008 at 21:11

    [...] next useful place I would point you is to this information on deprecated stuff.  There is a lot of stuff that’s been removed or replaced in 1.2, so if you are using any of [...]

  • olivier August 05, 2008 at 22:11

    Hello!
    i finally got an answer to my question: the field i wanted to change the size was mapped to a VARCHAR field type in my db. Cake took the length of the VARCHAR as the default length of the field (or “maxlength”, should I say).
    Thank you very much for your help.

    Olivier

  • cakebaker August 06, 2008 at 16:59

    @Olivier: Cool to hear you found an answer! Bake on :)

  • Waruna Geekiyanage October 23, 2008 at 08:22

    Eg.

    $recursive = -1;
    $conditions = array(‘Product.active’ => ’1′);
    $fields = array(‘Product.name’);
    $arr_products = $this->Product->find( ‘list’, array( ‘conditions’ => $conditions, ‘fields’ => $fields, ‘recursive’ => $recursive) );

  • Waruna Geekiyanage October 23, 2008 at 08:31

    $arr_products = $this->Product->find( ‘list’, array( ‘conditions’ => $conditions, ‘fields’ => $fields, ‘recursive’ => $recursive, ‘order’ => ‘Product.name ASC’ ) );

  • cakebaker October 23, 2008 at 19:00

    @Waruna: Hm, what do you want to say with your comments?

  • Keith March 17, 2009 at 21:18

    The new 1.2.1.8004 CSS sets the input & text field size to 100% in the css. You need to go in and remove that from the css and the size options parameter for your fields will work fine.

  • cakebaker March 18, 2009 at 18:13

    @Keith: Thanks for this hint, I wasn’t aware of it (I usually don’t use the CSS that comes with CakePHP).

  • Neil November 15, 2009 at 12:12

    findBySql() has also been deprecated. Use query().

  • cakebaker November 17, 2009 at 17:02

    @Neil: Yes, you are right, findBySql() is deprecated resp. no longer exists in the current versions (1.2.5 and 1.3alpha). Thanks for mentioning it.

  • Naveen December 15, 2009 at 10:19

    hi,
    am getting the following error.
    Undefined index: MailTrigger [APP\views\mails_triggers\index.ctp, line 131].

    MailTrigger is the name of my Model.

    in index.ctp

    I have done this before but, y do i keep getting the error with respect to the Model.

    My Model.

    Could you please provide me with some information on this.

  • cakebaker December 17, 2009 at 17:15

    @Naveen: Well, some parts of your comment got eaten by WordPress… So the only advice I can give you is to use the debug() function to see the structure of the data passed from the controller to your view.

    Hope this helps a bit!

Bake a comment




(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License