我知道这段代码:
$this->router->fetch_class(); // get current controller name
$this->router->fetch_method(); // get current method name
Run Code Online (Sandbox Code Playgroud)
我想要做的是获取当前控制器或特定控制器中可用的所有方法。有人有同样的经历吗?谢谢。
解决方案
我创建助手来列出特定控制器中的所有方法
function list_this_controllers_method_except($controller, $except = array())
{
$methods = array();
foreach(get_class_methods($controller) as $method)
{
if (!in_array($method, $except))
{
$methods[] = $method;
}
}
return $methods;
}
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
function CustomersController ($scope, $http) {
$http.get('/ci_angular/api/customers/').success(function(customers){
$scope.customers = customers;
});
$scope.addCustomer = function(){
var customer = {
customerName: $scope.customerNameText,
email: $scope.emailText,
address: $scope.addressText,
city: $scope.cityText,
state: $scope.stateText,
postalCode: $scope.postalCodeText,
country: $scope.countryText,
};
$scope.customers.push(customer);
// update 1
$http.post('/ci_angular/api/customers/customer', customer);
$scope.emptyCustomers= {};
$scope.reset = function() {
$scope.customers = angular.copy($scope.emptyCustomers);
};
// update 2
$http.post('/ci_angular/api/customers/customer', customer)
.success(function() {
$scope.emptyCustomers= {};
$scope.customerForm.$setPristine();
}
);
}
}
Run Code Online (Sandbox Code Playgroud)
在成功后,我想重置所有表单字段,但它不起作用,我的表单名称是customerForm,有什么我错过了吗?提前致谢
所以我有这个数组:
$data = array(
'item_1' => $this->input->post('item_1'),
'item_2' => $this->input->post('item_2'),
'item_3' => $this->input->post('item_3')
);
$this->session->set_userdata( 'items', $data );
Run Code Online (Sandbox Code Playgroud)
我想向该数组添加一个新项目,因此更新后的 userdata 数组将如下所示:
$data = array(
'item_1' => $this->input->post('item_1'),
'item_2' => $this->input->post('item_2'),
'item_3' => $this->input->post('item_3'),
'item_4' => $this->input->post('item_4')
);
$this->session->set_userdata( 'items', $data );
Run Code Online (Sandbox Code Playgroud)
怎么做,谢谢
我正在尝试重命名迁移文件以重新排序迁移,但我发现了一个错误.
我知道迁移文件的名称是基于时间戳生成的,例如:
m150311_012031_create_place_table.php
m150311_020901_create_meeting_table.php
Run Code Online (Sandbox Code Playgroud)
我忘记了meeting
在创建表之前我应该首先创建place
表,所以我要运行yii migrate/down all
以首先回滚迁移,我重命名文件以重新排序,如下所示:
m150311_012030_create_meeting_table.php
m150311_012031_create_place_table.php
Run Code Online (Sandbox Code Playgroud)
并运行,yii migrate up/all
但我收到此错误:
PHP Fatal error: Class 'm150311_012030_create_meeting_table' not found in C:\wamp\www\yii2advanced\vendor\yiisoft\yii2\console\controllers\MigrateController.php on line 113
Run Code Online (Sandbox Code Playgroud)
我认为composer dumpautoload
会解决这个问题,但没有任何反应.我知道我可以从重新开始删除并创建所有迁移,但是如果我已经创建了10个迁移文件,我忘了我应该在第二个订单上创建迁移.
这该怎么做?
我有这个字符串:
$hours = '7, 8, 12';
$hourData = explode(', ', $hours);
Run Code Online (Sandbox Code Playgroud)
如果我var_dump($hourData)
,它返回:
array(3) {
[0]=>
string(1) "7"
[1]=>
string(2) "8"
[2]=>
string(2) "12"
}
Run Code Online (Sandbox Code Playgroud)
我有这个代码:
<?php for ($i=0; $i <= 23 ; $i++) { ?>
<div class="fl">
<input type="checkbox" name="limit_hour[]" value="<?php echo $i ?>" class="fl limit_hour"
<!-- ======================================================================== -->
<?php echo (isset($hourData[$i]) && $i == $hourData[$i] ? 'checked' : '') ?>>
<!-- ======================================================================== -->
<span class="fl lmBox"><?php echo $i ?>:00 - <?php echo $i ?>:59</span>
</div>
<?php } …
Run Code Online (Sandbox Code Playgroud)