Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

The default Login Form - add default value's


Reply

19 Posts   3285 Views

Avatar
UncleCheese

10 August 2010 at 2:55am 4085 Posts

The Object::useCustomClass() needs to be in your _config.php. This needs to be in CustomLoginForm.php:

class MyLoginForm extends MemberLoginForm {
public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true) {
parent::_contstruct($controller, $name, $fields, $actions, $checkCurrentUser);
$this->Fields()->fieldByName('Email')->setValue('Some default value');
}
}

Avatar
borriej

10 August 2010 at 4:05am Community Member, 267 Posts

You mean the config should look like this?

Object::useCustomClass('MemberLoginForm', 'CustomLoginForm');
Object::add_extension('Group', 'GroupDecorator');
Object::useCustomClass('MemberLoginForm', 'MyLoginForm');

Placed you function inside CustomLoginForm.php

but website gives error :(

What to do?

Avatar
UncleCheese

10 August 2010 at 4:47am 4085 Posts

What does "gives error" mean?

Avatar
borriej

10 August 2010 at 5:02am Community Member, 267 Posts

The normal error from silverstripe when you have an error in your code.

You know:

WEBSITE ERROR

on a grey background in a blue-ish square.

Avatar
UncleCheese

10 August 2010 at 5:50am 4085 Posts

Get your site into dev mode so we can see the error.

Director::set_environment_type('dev');

You shouldn't be running in live mode while you're still developing.

Avatar
borriej

10 August 2010 at 7:48am (Last edited: 10 August 2010 7:49am), Community Member, 267 Posts

[User Error] Uncaught ReflectionException: Class MyLoginForm does not exist
GET /bedrijfsprofiel

Line 89 in /public/sites/www.url.nl/sapphire/core/Object.php
Source

80     * @param string $class the class name
81     * @param mixed $arguments,... arguments to pass to the constructor
82     * @return Object
83     */
84    public static function create() {
85       $args = func_get_args();
86       $class = self::getCustomClass(array_shift($args));
87       
88       if(version_compare(PHP_VERSION, '5.1.3', '>=')) {
89          $reflector = new ReflectionClass($class);
90          return $reflector->newInstanceArgs($args);
91       } else {
92          // we're using a PHP install that doesn't support ReflectionClass->newInstanceArgs()
93          
94          $args = $args + array_fill(0, 9, null);
95          return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]);

Avatar
UncleCheese

10 August 2010 at 8:10am 4085 Posts

Did you create MyLoginForm.php?

Avatar
borriej

10 August 2010 at 8:15am (Last edited: 10 August 2010 8:16am), Community Member, 267 Posts

At first i didn't create the MyLoginForm php, because the function was added on rule 1 of CustomLoginForm.php

Now i added the function to MyLoginForm.php - and deleted the function from customloginform.php

After dev/build

When I enter the page:

[User Error] Uncaught Exception: Object->__call(): the method '_contstruct' does not exist on ''
GET /bedrijfsprofiel

Line 576 in /public/sites/www.url.nl/sapphire/core/Object.php