qihuajun

第 655 位会员

会员
个人信息
  • 加入于 2016-12-02 10:53:15
  • 最后登录时间 6年前
个人成就
  • 发表文章次数 0
  • 发布回复次数 2
  • 个人主页浏览次数 0
关于yii2.0的crontab扩展6年前

正式的项目中不建议使用crontab管理任务,推荐使用Rundeck或者Azkaban

yii配置详解6年前

其实之所以能够实现上面的配置基础还是所有的组件类都继承自 yii\base\Component,而 yii\base\Component又继承自 yii\base\Object yii\base\Object是Yii中所有类的基类。在Yii中对象的创建都是用Yii::createObject方法创建的,createObject的方法说明如下:

 * Creates a new object using the given configuration.
 *
 * You may view this method as an enhanced version of the `new` operator.
 * The method supports creating an object based on a class name, a configuration array or
 * an anonymous function.
 *
 * Below are some usage examples:
 *
 * ```php
 * // create an object using a class name
 * $object = Yii::createObject('yii\db\Connection');
 *
 * // create an object using a configuration array
 * $object = Yii::createObject([
 *     'class' => 'yii\db\Connection',
 *     'dsn' => 'mysql:host=127.0.0.1;dbname=demo',
 *     'username' => 'root',
 *     'password' => '',
 *     'charset' => 'utf8',
 * ]);
 *
 * // create an object with two constructor parameters
 * $object = \Yii::createObject('MyClass', [$param1, $param2]);
 * ```
 *
 * Using [[\yii\di\Container|dependency injection container]], this method can also identify
 * dependent objects, instantiate them and inject them into the newly created object.
 *
 * @param string|array|callable $type the object type. This can be specified in one of the following forms:
 *
 * - a string: representing the class name of the object to be created
 * - a configuration array: the array must contain a `class` element which is treated as the object class,
 *   and the rest of the name-value pairs will be used to initialize the corresponding object properties
 * - a PHP callable: either an anonymous function or an array representing a class method (`[$class or $object, $method]`).
 *   The callable should return a new instance of the object being created.
 *
 * @param array $params the constructor parameters
 * @return object the created object
 * @throws InvalidConfigException if the configuration is invalid.
 * @see \yii\di\Container

也就是说通过传入类名和类的属性,调用这个方法即可生成对象。