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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

[solved] limit of silvertripe


Reply

19 Posts   2281 Views

Avatar
UncleCheese

1 April 2009 at 8:12am 4085 Posts

Le function correct est au-dessous:

function AgentSearchForm()
{
return new Form(
$this,
"AgentSearchForm",
new FieldSet(new TextField('Zip')),
new FieldSet(new FormAction('doAgentSearch','Search'))
); // ligne 27
}

Il semble que tu as bouge le ")" en lieu d'ajouter.

Avatar
astate

1 April 2009 at 8:44am Community Member, 35 Posts

ok, now i have a new search field.

where i write zip list of my agents ?

I read and read the code ... but

Avatar
UncleCheese

1 April 2009 at 8:55am 4085 Posts

Show me your Agent.php class.

Avatar
astate

1 April 2009 at 9:11am Community Member, 35 Posts

my agent.php [url]http://pastebin.com/m1ef6552d[/url]

Avatar
UncleCheese

1 April 2009 at 9:22am 4085 Posts

Yikes.

You have no custom fields for your object. You really should read the tutorials on extending a basic site. You're trying to do some pretty advanced techniques and you don't have the basics down yet.

class Agent extends Page {

static $db = array('Zip' => 'Text');

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new TextField('Zip','Zip codes'));
return $fields;

}

}

Then you need to update your function:

function doAgentSearch($data, $form)
{
// Ici je vais deviner un peu, puisque je ne connais pas ton modele data.

$zip = $data['Zip'];
if(is_numeric($zip)) {
if($agent = DataObject::get("Agent", "Zip LIKE '%$zip%'"))
Director::redirect($agent->Link());
else Director::redirect('agent-not-found'); // un page que tu as deja crée..
}
else Director::redirect('agent-not-found');

}

Then, run a /dev/build.

In the CMS now, you can list all of the zip codes in the Zip Codes field.

12345 53470 32470 43079

etc..

Avatar
astate

1 April 2009 at 9:56am Community Member, 35 Posts

I read and i think understant the tutorial 1 and 2.
Now it's don't work, but check this.

thanks

Avatar
astate

1 April 2009 at 11:14am (Last edited: 1 April 2009 1:39pm), Community Member, 35 Posts

When the Postal are good, i have error

this line of code give me a probleme in my Agent.php

Director::redirect($agent->Link());

[User Error] Object::__call() Method 'Link' not found in class 'DataObjectSet'
POST /agent/AgentSearchForm

Line 133 in /home/kbsecuri/www/sapphire/core/Object.php
Source

124
125          } else if($config['function_str']) {
126             $function = Object::$extraMethods[$this->class][strtolower($methodName)]['function'] = create_function('$obj, $args', $config['function_str']);
127             return $function($this, $args);
128
129          } else {
130             user_error("Object::__call() Method '$methodName' in class '$this->class' an invalid format: " . var_export(Object::$extraMethods[$this->class][$methodName],true), E_USER_ERROR);
131          }
132       } else {
133          user_error("Object::__call() Method '$methodName' not found in class '$this->class'", E_USER_ERROR);
134       }
135    }
136

Avatar
UncleCheese

1 April 2009 at 2:53pm 4085 Posts

Try DataObject::get_one() instead of DataObject::get()\