tôi chỉ thực hiện không gian tên trong ứng dụng nhỏ của tôi như được nêu ở đây: http://www.yiiframework.com/doc/guide/1.1/en/basics.namespaceNamespaces trong PHP ngăn chặn sử dụng các chức năng tĩnh Yii
Tôi đang chạy vào một vấn đề mà điều khiển của tôi sẽ không còn truy cập Yii::app()->getRequest();
nói rằng nó không thể tìm thấy include(C:\Users\bkuhl\htdocs\instaLabel\application\protected\components\Yii.php): failed to open stream: No such file or directory
.
Tôi nhận ra đó là vì tôi đã khai báo không gian tên là ứng dụng/thành phần. Nhưng tôi không chắc chắn làm thế nào để làm việc xung quanh này ...
<?php
namespace application\components;
/**
* Controller is the customized base controller class.
* All controller classes for this application should extend from this base class.
*/
class Controller extends \CController {
/* @var $request CHttpRequest */
protected $request = null;
/**
* @var string the default layout for the controller view. Defaults to '//layouts/column1',
* meaning using a single column layout. See 'protected/views/layouts/column1.php'.
*/
public $layout='//layouts/column1';
/**
* @var array context menu items. This property will be assigned to {@link CMenu::items}.
*/
public $menu=array();
/**
* @var array the breadcrumbs of the current page. The value of this property will
* be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
* for more details on how to specify this property.
*/
public $breadcrumbs=array();
public function __construct ($id, $module = null) {
parent::__construct($id, $module);
$this->request = Yii::app()->getRequest();
}
tốt hơn khi bạn có nhiều lần xuất hiện của 'Yii' trong lớp. –
Giống như 'sử dụng Yii/Yii;'? – Webnet
@Webnet: Đó không phải là cú pháp hợp lệ. Ngay cả khi nó là nó sẽ ám chỉ một lớp 'Yii' bên trong một không gian tên' Yii'. Không có không gian tên 'Yii', vì vậy nó sẽ là vô nghĩa trong mọi trường hợp. – Jon