Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use Yii namespace

Tags:

php

yii

I'm having I confusion in understanding the namespace from the Yii documentation as their are not enough example to understand, as I'm new to Yii framework please give some easy and detailed examples so that I can understand it's purpose.

like image 804
tariq Avatar asked May 09 '12 09:05

tariq


People also ask

What is Yii2 namespace?

A namespace refers to a logical grouping of some class names so that they can be differentiated from other class names even if their names are the same. Do not confuse path alias with namespace. A path alias is merely a convenient way of naming a file or directory.

What is Yii used for?

Yii is a high-performance, component-based PHP framework for developing large-scale Web applications rapidly. It enables maximum reusability in Web programming and can significantly accelerate your Web application development process. The name Yii (pronounced Yee or [ji:] ) is an acroynym for "Yes It Is!".

What is difference between Yii and Yii2?

Conceptually Yii1 and Yii2 are quite similar, however Yii2 runs on newer PHP versions and utilizes namespaces, traits etc. Yii2 has also support for dependency injection through $container singleton available after initializing the framework.


1 Answers

You may try read this documentation http://yiiframework.ru/doc/guide/en/basics.namespace In general Yii namespaces - it is aliases for folders. I.E.

  'aliases' => array(
            'frontend' => dirname(__FILE__) . '/../..' . '/frontend',
            'common' => dirname(__FILE__) . '/../..' . '/common',
            'backend' => dirname(__FILE__) . '/../..' . '/backend',
            'vendor' => dirname(__FILE__) . '/../..' . '/common/lib/vendor'
  ),

  ...

  'import' => array(
           'common.extensions.components.*',
           'common.components.*',
           'common.helpers.*',
           'common.models.*',
           'application.controllers.*',

// In result "common" = dirname(__FILE__) . '/../..' . '/common'
like image 158
Denis Tuxoff Avatar answered Sep 23 '22 00:09

Denis Tuxoff