Commit c699213c by 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
.settings
# windows thumbnail cache
Thumbs.db
\ No newline at end of file
Thumbs.db
# composer vendor dir
vendor
\ No newline at end of file
......@@ -39,6 +39,9 @@ $this->registerAssetBundle('app');
<!-- /.navbar -->
</div>
<?php $this->widget('yii\widgets\Breadcrumbs', array(
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(),
)); ?>
<?php echo $content; ?>
<hr>
......
......@@ -4,6 +4,7 @@ use yii\helpers\Html;
* @var yii\base\View $this
*/
$this->title = 'About';
$this->params['breadcrumbs'][] = $this->title;
?>
<h1><?php echo Html::encode($this->title); ?></h1>
......
......@@ -6,6 +6,7 @@ use yii\helpers\Html;
* @var app\models\ContactForm $model
*/
$this->title = 'Contact';
$this->params['breadcrumbs'][] = $this->title;
?>
<h1><?php echo Html::encode($this->title); ?></h1>
......
......@@ -6,6 +6,7 @@ use yii\helpers\Html;
* @var app\models\LoginForm $model
*/
$this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
?>
<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 @@
* [Performance Tuning](performance.md)
* [Testing](testing.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)
......@@ -4,6 +4,8 @@
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii;
use yii\base\Exception;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
......@@ -60,7 +62,7 @@ class YiiBase
*/
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;
/**
......
......@@ -90,6 +90,7 @@ class Component extends Object
// as behavior: attach behavior
$name = trim(substr($name, 3));
$this->attachBehavior($name, $value instanceof Behavior ? $value : Yii::createObject($value));
return;
} else {
// behavior property
$this->ensureBehaviors();
......
......@@ -72,23 +72,21 @@ class View extends Component
/**
* @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.
* For example,
*
* ~~~
* array(
* 'tpl' => array(
* 'class' => 'yii\renderers\SmartyRenderer',
* ),
* 'twig' => array(
* 'class' => 'yii\renderers\TwigRenderer',
* ),
* )
* ~~~
* 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.
*
* If no renderer is available for the given view file, the view file will be treated as a normal PHP
* 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.
* If not set, it means theming is not enabled.
......
......@@ -8,6 +8,7 @@
namespace yii\db;
use yii\base\InvalidConfigException;
use yii\base\Model;
use yii\base\InvalidParamException;
use yii\base\ModelEvent;
......@@ -112,6 +113,7 @@ class ActiveRecord extends Model
* @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
* returned (null will be returned if there is no matching).
* @throws InvalidConfigException if the AR class does not have a primary key
* @see createQuery()
*/
public static function find($q = null)
......@@ -122,7 +124,11 @@ class ActiveRecord extends Model
} elseif ($q !== null) {
// query by primary key
$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;
}
......
......@@ -8,7 +8,7 @@
namespace yii\helpers\base;
use yii\base\InvalidParamException;
use yii\helpers\JsExpression;
use yii\web\JsExpression;
/**
* Json is a helper class providing JSON data encoding and decoding.
......
......@@ -9,7 +9,7 @@ namespace yii\validators;
use Yii;
use yii\helpers\Html;
use yii\helpers\JsExpression;
use yii\web\JsExpression;
use yii\helpers\Json;
/**
......
......@@ -9,7 +9,7 @@ namespace yii\validators;
use Yii;
use yii\helpers\Html;
use yii\helpers\JsExpression;
use yii\web\JsExpression;
use yii\helpers\Json;
/**
......
......@@ -10,7 +10,7 @@ namespace yii\validators;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\Html;
use yii\helpers\JsExpression;
use yii\web\JsExpression;
use yii\helpers\Json;
/**
......
......@@ -9,7 +9,7 @@ namespace yii\validators;
use Yii;
use yii\helpers\Html;
use yii\helpers\JsExpression;
use yii\web\JsExpression;
use yii\helpers\Json;
/**
......
......@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\helpers;
namespace yii\web;
use yii\base\Object;
......
......@@ -10,7 +10,7 @@ use yii\base\Component;
use yii\db\ActiveRecord;
use yii\helpers\Html;
use yii\base\Model;
use yii\helpers\JsExpression;
use yii\web\JsExpression;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
......
......@@ -12,7 +12,6 @@ use yii\base\Widget;
use yii\base\Model;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\helpers\JsExpression;
/**
* 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));
}
}
}
......@@ -18,7 +18,7 @@ require(__DIR__ . '/YiiBase.php');
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Yii extends YiiBase
class Yii extends \yii\YiiBase
{
}
......
......@@ -27,10 +27,21 @@ REQUIREMENTS
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
------------------
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)
* [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 @@
namespace yiiunit\framework\helpers;
use yii\helpers\Json;
use yii\helpers\JsExpression;
use yii\web\JsExpression;
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