Skip to content

Commit

Permalink
moving a few things, renaming YForm_Element::$_options to $_config
Browse files Browse the repository at this point in the history
  • Loading branch information
zeelot committed Feb 14, 2010
1 parent 31c9f85 commit 0bfb365
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 23 deletions.
6 changes: 4 additions & 2 deletions classes/controller/yform/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

class Controller_YForm_Demo extends Controller_Yuriko_Template {

public function action_payment()
public function action_index()
{
$this->template->content = View::factory('yform/demo/payment')
$view = $this->request->param('view');

$this->template->content = View::factory('yform/demo/'.$view)
->bind('post', $_POST)
->bind('errors', $errors);
$this->title = 'YForm Demo!';
Expand Down
38 changes: 22 additions & 16 deletions classes/yuriko/yform/element.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

abstract class Yuriko_YForm_Element {

protected $_options = array();
protected $_config = array();

/**
* Values directly accessible by __get()
Expand Down Expand Up @@ -44,7 +44,7 @@ public function __construct(YForm_Settings $settings, $name)
'YForm_',
), '', get_class($this)));

$this->_options += array
$this->_config += array
(
'theme' => $settings->theme,
'view' => $settings->view($type),
Expand Down Expand Up @@ -120,22 +120,20 @@ public function set($name, $value = NULL)
return $this;
}

public function set_option($name, $value)
public function config($name, $value)
{
if (is_array($name))
{
foreach ($name as $key => $value)
{
$this->_options[$key] = $value;
}
}
else
{
$this->_options[$name] = $value;
}
$this->_config[$name] = $value;

return $this;
}

public function configs(array $configs)
{
foreach ($configs as $key => $value)
{
$this->_config[$key] = $value;
}
}

/**
* This is an alias for YForm_Attributes::set() which allows you
Expand All @@ -146,12 +144,20 @@ public function set_option($name, $value)
* @param mixed $value
* @return self
*/
public function set_attribute($key, $value)
public function attribute($key, $value)
{
$this->attributes->set($key, $value);

return $this;
}

public function attributes(array $attributes)
{
foreach ($attributes as $key => $value)
{
$this->attributes->set($key, $value);
}
}

/**
* Adds a message to this element in the group specified in
Expand Down Expand Up @@ -251,7 +257,7 @@ public function render()
*/
public function view()
{
return 'yform/themes/'.$this->_options['theme'].'/'.$this->_options['view'];
return 'yform/themes/'.$this->_config['theme'].'/'.$this->_config['view'];
}

} // End Yuriko_YForm_Element
2 changes: 1 addition & 1 deletion classes/yuriko/yform/label.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(YForm_Settings $settings, $for, $text)
->set('for', $for),
);

$this->_options += array
$this->_config += array
(
'theme' => $settings->theme,
'view' => $settings->view(strtolower(str_replace('YForm_', '', get_class($this)))),
Expand Down
2 changes: 1 addition & 1 deletion init.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license http://yurikocms.com/license
*/

Route::set('yform', 'yform(/<controller>(/<action>))')
Route::set('yform', 'yform(/<controller>(/<view>))')
->defaults(array(
'controller' => 'demo',
'action' => 'index',
Expand Down
6 changes: 3 additions & 3 deletions views/yform/demo/payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

<?php echo $form->text('name')
// will look in views/yform/themes/default for this field
->set_option('theme', 'default')
->config('theme', 'default')
// will render with theme path from above + input/text as the full path to view file
->set_option('view', 'input/text')
->config('view', 'input/text')
// you can also pass any value into the corresponding view
->set('foo', 'bar')
// you can alter the attributes for the element
->set_attribute('value', 'Lorenzo')
->attribute('value', 'Lorenzo')
// pass in message objects
->add_message($form->message('info', 'Info Text')
// this message object can have methods chained to it as well
Expand Down
17 changes: 17 additions & 0 deletions views/yform/demo/simple.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Sample Payment form using YForm
*/
?>

<?php

// uses the default config group
$form = YForm::factory('payment');

?>

<?php echo $form->open(); ?>
<?php echo $form->text('name'); ?>
<?php echo $form->submit('submit'); ?>
<?php echo $form->close(); ?>

0 comments on commit 0bfb365

Please sign in to comment.