18. What’s bad in Yii 1.1?
• AR (finder and record are the same object,
some API).
• Some classes are in strange places.
• More small things.
The biggest issue is
BC
20. Yii 2 team
—3 active core developers: qiang, samdark,
mdomba.
—github.
21. —PHP 5.3.8+ —Better structure
—All classes are —Less entities
namespaced (yii) and —Keep good ideas
w/o prefix
—PSR-0
v2
22. Documentation
—Larry Ullman, author of 22 excellent IT-books
and a great article series about Yii will write a
book about Yii2 + will participate in official
documentation writing.
—API docs will be at least same quality as 1.1.
—Code style guide.
—There’s a plan to release documentation tool
to the public.
23. Yii2: base
— Aliases in form of class MyComponent extends
@yii/base/Component yiibaseObject
{
— CComponent → public $x;
Object + Component public function __construct($a, $b)
— SPL replaced most of {
collections //…
}
— Removed
}
CFormModel. Now
you can use Model $component = MyComponent::newInstance(
directly. array('x'=>10),
'a', 'b'
);
24. Yii2: View Object
—render(), widget(),
beginCache() →
viewObject
—In a View: $owner =
class that uses view
—$this = View.
—No need for renderer.
—Can be used in console
applications.
—CHtml is still there.
25. Yii2: events
$post->on('add', • No need to
function($event) { ... explicitly declare
}); before raising
• jQuery-like syntax
$post->trigger('add', • Behaviors instead of
new Event($this)); filters
$post->off('add',
$callback);
$handlers = $post-
>getEventHandlers('add'
);
27. Yii2: AR
$customer = Customer::find(2) – Finder / Model
->active() – Can create your own
->one(); finder
$customer->name = 'Qiang';
– ::model()
$customer->save();
– Auto quoting.
$customers = Customer::find() – Method chains.
->order('id')
->asArray(true)
->all();
28. Yii2: AR
$postFinder = Post::find() – Criteria
->where(array( – Can merge two finders
'active' => true
– Can add conditions on
));
the fly
if($isPrivate) {
$postFinder->addWhere(array(
'createdBy' => $userId,
));
}
$posts = $postFinder
->mergeWith($anotherFinder)
->all();
29. Yii2: AR
class Customer extends ActiveRecord {
– tableName(), const STATUS_ACTIVE = 1;
relations(), scopes() =
public static function tableName() {
static. return 'tbl_customer';
– Relations are }
HAS_ONE, public static function relations() {
HAS_MANY. return array(
'orders:Order[]' => array(
– link = FKs => 'id'),
'link' => array('customer_id'
– via = through );
),
– Anonymous functions }
for scopes. public static function scopes() {
– "@." and "?" tokens: return array(
'active' => function($q) {
own table, external return $q-
>andWhere('@.`status` = ' . self::STATUS_ACTIVE);
table. },
);
}
}
30. Yii2: AR
$customers = $customers =
Customer::find()-> Customer::find()->active()
asArray()->all(); ->all();
foreach (Customer::find() $customers =
as $customer) Customer::find()
->where('name like :name',
$count = Customer::count() array(
->value(); ':name' => '%customer%‘
))->order('id')->all();
31. TODO (if there will be enough time)
• HTTP (CURL) wrapper • jQueryUI-based widgets
• Package manager • Commercial support
• Mailer
• Twitter Bootstrap
• Debug toolbar
• Console requirements
• More helpers
33. When?
Before alpha code will be • Base for caching
put into public github • Base for i18n
repository we need to • Controller + webapp
finish at least these
things→ • Base for widgets
• URL manager