Commit c699213c authored by sensorario's avatar sensorario

Merge http://github.com/yiisoft/yii2

* http://github.com/yiisoft/yii2: (23 commits)
  move JsExpression to web.
  Fixes issue #155.
  Fixes the variable name
  Added twig, smarty and php-markdown dependencies, vendor is gitignored now
  added composer.json
  fix
  fix
  Wrapped code with github-style blocks with PHP highlighting
  Fixed typo
  Controllers section example fix
  Renamed YiiBase to \yii\YiiBase.
  Added namespace section.
  Added dirty attribute description.
  Fixed doc about renderers.
  Finished the initial draft of upgrading instructions
  Fix attaching behavior via config
  Changed default value of View::renderers.
  Fix attaching behavior via config
  Menu WIP
  upgrading instructions WIP
  ...
parents d0a634b9 dd596914
...@@ -10,4 +10,7 @@ nbproject ...@@ -10,4 +10,7 @@ nbproject
.settings .settings
# windows thumbnail cache # windows thumbnail cache
Thumbs.db Thumbs.db
\ No newline at end of file
# composer vendor dir
vendor
\ No newline at end of file
...@@ -39,6 +39,9 @@ $this->registerAssetBundle('app'); ...@@ -39,6 +39,9 @@ $this->registerAssetBundle('app');
<!-- /.navbar --> <!-- /.navbar -->
</div> </div>
<?php $this->widget('yii\widgets\Breadcrumbs', array(
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(),
)); ?>
<?php echo $content; ?> <?php echo $content; ?>
<hr> <hr>
......
...@@ -4,6 +4,7 @@ use yii\helpers\Html; ...@@ -4,6 +4,7 @@ use yii\helpers\Html;
* @var yii\base\View $this * @var yii\base\View $this
*/ */
$this->title = 'About'; $this->title = 'About';
$this->params['breadcrumbs'][] = $this->title;
?> ?>
<h1><?php echo Html::encode($this->title); ?></h1> <h1><?php echo Html::encode($this->title); ?></h1>
......
...@@ -6,6 +6,7 @@ use yii\helpers\Html; ...@@ -6,6 +6,7 @@ use yii\helpers\Html;
* @var app\models\ContactForm $model * @var app\models\ContactForm $model
*/ */
$this->title = 'Contact'; $this->title = 'Contact';
$this->params['breadcrumbs'][] = $this->title;
?> ?>
<h1><?php echo Html::encode($this->title); ?></h1> <h1><?php echo Html::encode($this->title); ?></h1>
......
...@@ -6,6 +6,7 @@ use yii\helpers\Html; ...@@ -6,6 +6,7 @@ use yii\helpers\Html;
* @var app\models\LoginForm $model * @var app\models\LoginForm $model
*/ */
$this->title = 'Login'; $this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
?> ?>
<h1><?php echo Html::encode($this->title); ?></h1> <h1><?php echo Html::encode($this->title); ?></h1>
......
{
"name": "yiisoft/yii2",
"description": "Yii2 Web Programming Framework",
"keywords": ["yii", "framework"],
"homepage": "http://www.yiiframework.com/",
"type": "library",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Qiang Xue",
"email": "qiang.xue@gmail.com",
"homepage": "http://www.yiiframework.com/",
"role": "Founder and project lead"
},
{
"name": "Alexander Makarov",
"email": "sam@rmcreative.ru",
"homepage": "http://rmcreative.ru/",
"role": "Core framework development"
},
{
"name": "Maurizio Domba",
"homepage": "http://mdomba.info/",
"role": "Core framework development"
},
{
"name": "Carsten Brandt",
"email": "mail@cebe.cc",
"homepage": "http://cebe.cc/",
"role": "Core framework development"
},
{
"name": "Timur Ruziev",
"email": "resurtm@gmail.com",
"homepage": "http://resurtm.com/",
"role": "Core framework development"
},
{
"name": "Paul Klimov",
"email": "klimov.paul@gmail.com",
"role": "Core framework development"
},
{
"name": "Wei Zhuo",
"email": "weizhuo@gmail.com",
"role": "Project site maintenance and development"
},
{
"name": "Sebastián Thierer",
"email": "sebas@artfos.com",
"role": "Component development"
},
{
"name": "Jeffrey Winesett",
"email": "jefftulsa@gmail.com",
"role": "Documentation and marketing"
}
],
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"bin": [
"framework/yiic"
],
"require": {
"php": ">=5.3.0",
"michelf/php-markdown": "1.3",
"twig/twig": "1.12.*",
"smarty/smarty": "3.1.*"
}
}
...@@ -27,4 +27,4 @@ ...@@ -27,4 +27,4 @@
* [Performance Tuning](performance.md) * [Performance Tuning](performance.md)
* [Testing](testing.md) * [Testing](testing.md)
* [Automatic Code Generation](gii.md) * [Automatic Code Generation](gii.md)
* [Upgrading from 1.1 to 2.0](upgrade.md) * [Upgrading from 1.1 to 2.0](upgrade-from-v1.md)
This diff is collapsed.
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii;
use yii\base\Exception; use yii\base\Exception;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
use yii\base\InvalidParamException; use yii\base\InvalidParamException;
...@@ -60,7 +62,7 @@ class YiiBase ...@@ -60,7 +62,7 @@ class YiiBase
*/ */
public static $enableIncludePath = true; public static $enableIncludePath = true;
/** /**
* @var yii\console\Application|yii\web\Application the application instance * @var \yii\console\Application|\yii\web\Application the application instance
*/ */
public static $app; public static $app;
/** /**
......
...@@ -90,6 +90,7 @@ class Component extends Object ...@@ -90,6 +90,7 @@ class Component extends Object
// as behavior: attach behavior // as behavior: attach behavior
$name = trim(substr($name, 3)); $name = trim(substr($name, 3));
$this->attachBehavior($name, $value instanceof Behavior ? $value : Yii::createObject($value)); $this->attachBehavior($name, $value instanceof Behavior ? $value : Yii::createObject($value));
return;
} else { } else {
// behavior property // behavior property
$this->ensureBehaviors(); $this->ensureBehaviors();
......
...@@ -72,23 +72,21 @@ class View extends Component ...@@ -72,23 +72,21 @@ class View extends Component
/** /**
* @var array a list of available renderers indexed by their corresponding supported file extensions. * @var array a list of available renderers indexed by their corresponding supported file extensions.
* Each renderer may be a view renderer object or the configuration for creating the renderer object. * Each renderer may be a view renderer object or the configuration for creating the renderer object.
* For example, * The default setting supports both Smarty and Twig (their corresponding file extension is "tpl"
* * and "twig" respectively. Please refer to [[SmartyRenderer]] and [[TwigRenderer]] on how to install
* ~~~ * the needed libraries for these template engines.
* array(
* 'tpl' => array(
* 'class' => 'yii\renderers\SmartyRenderer',
* ),
* 'twig' => array(
* 'class' => 'yii\renderers\TwigRenderer',
* ),
* )
* ~~~
* *
* If no renderer is available for the given view file, the view file will be treated as a normal PHP * If no renderer is available for the given view file, the view file will be treated as a normal PHP
* and rendered via [[renderPhpFile()]]. * and rendered via [[renderPhpFile()]].
*/ */
public $renderers = array(); public $renderers = array(
'tpl' => array(
'class' => 'yii\renderers\SmartyRenderer',
),
'twig' => array(
'class' => 'yii\renderers\TwigRenderer',
),
);
/** /**
* @var Theme|array the theme object or the configuration array for creating the theme object. * @var Theme|array the theme object or the configuration array for creating the theme object.
* If not set, it means theming is not enabled. * If not set, it means theming is not enabled.
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace yii\db; namespace yii\db;
use yii\base\InvalidConfigException;
use yii\base\Model; use yii\base\Model;
use yii\base\InvalidParamException; use yii\base\InvalidParamException;
use yii\base\ModelEvent; use yii\base\ModelEvent;
...@@ -112,6 +113,7 @@ class ActiveRecord extends Model ...@@ -112,6 +113,7 @@ class ActiveRecord extends Model
* @return ActiveQuery|ActiveRecord|null When `$q` is null, a new [[ActiveQuery]] instance * @return ActiveQuery|ActiveRecord|null When `$q` is null, a new [[ActiveQuery]] instance
* is returned; when `$q` is a scalar or an array, an ActiveRecord object matching it will be * is returned; when `$q` is a scalar or an array, an ActiveRecord object matching it will be
* returned (null will be returned if there is no matching). * returned (null will be returned if there is no matching).
* @throws InvalidConfigException if the AR class does not have a primary key
* @see createQuery() * @see createQuery()
*/ */
public static function find($q = null) public static function find($q = null)
...@@ -122,7 +124,11 @@ class ActiveRecord extends Model ...@@ -122,7 +124,11 @@ class ActiveRecord extends Model
} elseif ($q !== null) { } elseif ($q !== null) {
// query by primary key // query by primary key
$primaryKey = static::primaryKey(); $primaryKey = static::primaryKey();
return $query->where(array($primaryKey[0] => $q))->one(); if (isset($primaryKey[0])) {
return $query->where(array($primaryKey[0] => $q))->one();
} else {
throw new InvalidConfigException(get_called_class() . ' must have a primary key.');
}
} }
return $query; return $query;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace yii\helpers\base; namespace yii\helpers\base;
use yii\base\InvalidParamException; use yii\base\InvalidParamException;
use yii\helpers\JsExpression; use yii\web\JsExpression;
/** /**
* Json is a helper class providing JSON data encoding and decoding. * Json is a helper class providing JSON data encoding and decoding.
......
...@@ -9,7 +9,7 @@ namespace yii\validators; ...@@ -9,7 +9,7 @@ namespace yii\validators;
use Yii; use Yii;
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\JsExpression; use yii\web\JsExpression;
use yii\helpers\Json; use yii\helpers\Json;
/** /**
......
...@@ -9,7 +9,7 @@ namespace yii\validators; ...@@ -9,7 +9,7 @@ namespace yii\validators;
use Yii; use Yii;
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\JsExpression; use yii\web\JsExpression;
use yii\helpers\Json; use yii\helpers\Json;
/** /**
......
...@@ -10,7 +10,7 @@ namespace yii\validators; ...@@ -10,7 +10,7 @@ namespace yii\validators;
use Yii; use Yii;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\JsExpression; use yii\web\JsExpression;
use yii\helpers\Json; use yii\helpers\Json;
/** /**
......
...@@ -9,7 +9,7 @@ namespace yii\validators; ...@@ -9,7 +9,7 @@ namespace yii\validators;
use Yii; use Yii;
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\JsExpression; use yii\web\JsExpression;
use yii\helpers\Json; use yii\helpers\Json;
/** /**
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\helpers; namespace yii\web;
use yii\base\Object; use yii\base\Object;
......
...@@ -10,7 +10,7 @@ use yii\base\Component; ...@@ -10,7 +10,7 @@ use yii\base\Component;
use yii\db\ActiveRecord; use yii\db\ActiveRecord;
use yii\helpers\Html; use yii\helpers\Html;
use yii\base\Model; use yii\base\Model;
use yii\helpers\JsExpression; use yii\web\JsExpression;
/** /**
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
......
...@@ -12,7 +12,6 @@ use yii\base\Widget; ...@@ -12,7 +12,6 @@ use yii\base\Widget;
use yii\base\Model; use yii\base\Model;
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\Json; use yii\helpers\Json;
use yii\helpers\JsExpression;
/** /**
* ActiveForm ... * ActiveForm ...
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\widgets;
use Yii;
use yii\base\Widget;
use yii\base\InvalidConfigException;
use yii\helpers\Html;
/**
* Breadcrumbs displays a list of links indicating the position of the current page in the whole site hierarchy.
*
* For example, breadcrumbs like "Home / Sample Post / Edit" means the user is viewing an edit page
* for the "Sample Post". He can click on "Sample Post" to view that page, or he can click on "Home"
* to return to the homepage.
*
* To use Breadcrumbs, you need to configure its [[links]] property, which specifiesthe links to be displayed. For example,
*
* ~~~
* $this->widget('yii\widgets\Breadcrumbs', array(
* 'links' => array(
* array('label' => 'Sample Post', 'url' => array('post/edit', 'id' => 1)),
* 'Edit',
* ),
* ));
* ~~~
*
* Because breadcrumbs usually appears in nearly every page of a website, you may consider place it in a layout view.
* You can then use a view parameter (e.g. `$this->params['breadcrumbs']`) to configure the links in different
* views. In the layout view, you assign this view parameter to the [[links]] property like the following:
*
* ~~~
* $this->widget('yii\widgets\Breadcrumbs', array(
* 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(),
* ));
* ~~~
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Breadcrumbs extends Widget
{
/**
* @var string the name of the breadcrumb container tag.
*/
public $tag = 'ul';
/**
* @var array the HTML attributes for the breadcrumb container tag.
*/
public $options = array('class' => 'breadcrumb');
/**
* @var boolean whether to HTML-encode the link labels.
*/
public $encodeLabels = true;
/**
* @var string the first hyperlink in the breadcrumbs (called home link).
* If this property is not set, it will default to a link pointing to [[\yii\web\Application::homeUrl]]
* with the label 'Home'. If this property is false, the home link will not be rendered.
*/
public $homeLink;
/**
* @var array list of links to appear in the breadcrumbs. If this property is empty,
* the widget will not render anything. Each array element represents a single link in the breadcrumbs
* with the following structure:
*
* ~~~
* array(
* 'label' => 'label of the link', // required
* 'url' => 'url of the link', // optional, will be processed by Html::url()
* )
* ~~~
*
* If a link is active, you only need to specify its "label", and instead of writing `array('label' => $label)`,
* you should simply use `$label`.
*/
public $links = array();
/**
* @var string the template used to render each inactive item in the breadcrumbs. The token `{link}`
* will be replaced with the actual HTML link for each inactive item.
*/
public $itemTemplate = "<li>{link} <span class=\"divider\">/</span></li>\n";
/**
* @var string the template used to render each active item in the breadcrumbs. The token `{link}`
* will be replaced with the actual HTML link for each active item.
*/
public $activeItemTemplate = "<li class=\"active\">{link}</li>\n";
/**
* Renders the widget.
*/
public function run()
{
if (empty($this->links)) {
return;
}
$links = array();
if ($this->homeLink === null) {
$links[] = $this->renderItem(array(
'label' => Yii::t('yii|Home'),
'url' => Yii::$app->homeUrl,
), $this->itemTemplate);
} elseif ($this->homeLink !== false) {
$links[] = $this->renderItem($this->homeLink, $this->itemTemplate);
}
foreach ($this->links as $link) {
if (!is_array($link)) {
$link = array('label' => $link);
}
$links[] = $this->renderItem($link, isset($link['url']) ? $this->itemTemplate : $this->activeItemTemplate);
}
echo Html::tag($this->tag, implode('', $links), $this->options);
}
/**
* Renders a single breadcrumb item.
* @param array $link the link to be rendered. It must contain the "label" element. The "url" element is optional.
* @param string $template the template to be used to rendered the link. The token "{link}" will be replaced by the link.
* @return string the rendering result
* @throws InvalidConfigException if `$link` does not have "label" element.
*/
protected function renderItem($link, $template)
{
if (isset($link['label'])) {
$label = $this->encodeLabels ? Html::encode($link['label']) : $link['label'];
} else {
throw new InvalidConfigException('The "label" element is required for each link.');
}
if (isset($link['url'])) {
return strtr($template, array('{link}' => Html::a($label, $link['url'])));
} else {
return strtr($template, array('{link}' => $label));
}
}
}
This diff is collapsed.
...@@ -18,7 +18,7 @@ require(__DIR__ . '/YiiBase.php'); ...@@ -18,7 +18,7 @@ require(__DIR__ . '/YiiBase.php');
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class Yii extends YiiBase class Yii extends \yii\YiiBase
{ {
} }
......
...@@ -27,10 +27,21 @@ REQUIREMENTS ...@@ -27,10 +27,21 @@ REQUIREMENTS
The minimum requirement by Yii is that your Web server supports PHP 5.3.?. The minimum requirement by Yii is that your Web server supports PHP 5.3.?.
DOCUMENTATION
-------------
For 1.1 users, you may refer to [Upgrading from Yii 1.1](docs/guide/upgrade-from-v1.md)
to have a general idea of what has changed in 2.0.
We are writing more documentation to get you started and learn more in depth.
HOW TO PARTICIPATE HOW TO PARTICIPATE
------------------ ------------------
You are welcome to participate in Yii 2 development in the following ways: **Your participation to Yii 2 development is very welcome!**
You may participate in the following ways:
* [Report issues](https://github.com/yiisoft/yii2/issues) * [Report issues](https://github.com/yiisoft/yii2/issues)
* [Give us feedback or start a design discussion](http://www.yiiframework.com/forum/index.php/forum/42-design-discussions-for-yii-20/) * [Give us feedback or start a design discussion](http://www.yiiframework.com/forum/index.php/forum/42-design-discussions-for-yii-20/)
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
namespace yiiunit\framework\helpers; namespace yiiunit\framework\helpers;
use yii\helpers\Json; use yii\helpers\Json;
use yii\helpers\JsExpression; use yii\web\JsExpression;
class JsonTest extends \yii\test\TestCase class JsonTest extends \yii\test\TestCase
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment