我的视图控制器中有一个表(我们称之为TVC1).我在TVC1中使用了行,因此除了TVC1上的数据之外,用户还可以输入更多数据.因此,当有人在TVC1中点击特定行时,它将显示另一个视图控制器(让我们称之为TVC2).但是,当显示TVC2时,TVC1中的所有数据都被清除.如何在TVC1中保存数据?我应该通过应用代表进行吗?
DescriptionInputViewController *descriptionController = [[DescriptionInputViewController alloc]
initWithNibName:@"DescriptionInputView"
bundle:nil];
[self presentModalViewController:navController animated:YES];
[self.navigationController pushViewController:descriptionController animated:YES];
[descriptionController release];
Run Code Online (Sandbox Code Playgroud) 我在所有控制器中都需要相同的2行,每个控制器都有自己的初始化逻辑,但这两行对所有控制器都是通用的.
public function init()
{
$fm =$this->_helper->getHelper('FlashMessenger');
$this->view->messages = $fm->getMessages();
}
Run Code Online (Sandbox Code Playgroud)
如何避免重复代码?
更新:
好吧,FlashMessenger只是一个例子,假设我需要在每个动作中写一个日志行,除了'someAction'@'someController'.所以新的共同线应该是.
$this->logger = new Zend_Log();
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH.'/../logs/log.txt');
$this->logger->addWriter($writer);
$this->logger->log('Some Message',Zend_Log::DEBUG);
Run Code Online (Sandbox Code Playgroud)
问题是,我应该在哪里放置这些行,以避免在每个控制器的所有init()中重复它们.这些行应该放在bootstrap?如果是这样:如何跳过'someAction'的日志行.或者我应该实现'BaseController'并使我的所有控制器从它扩展.如果是这样:我如何自动加载它?(致命错误:未找到类'BaseController').
我创建了一个注册表单,然后将数据发送到控制器.
我想将此数据插入3个不同的表(模型).
怎么能实现这一目标?
我正在构建我在Expression Engine中的第一个站点,我想知道如何在EE中使用自定义控制器,就像我在Codeigniter中那样,或者什么是EE等价物?
将其添加到我display函数的末尾之后app/controllers/pages_controller.php,
// grab all message lists
$this->loadModel('MessageList');
$this->set('messageLists', $this->MessageList->find('all'));
Run Code Online (Sandbox Code Playgroud)
我尝试app/views/pages/home.ctp像这样访问它
<?php
foreach($messageLists as $messageList) {
print_r($messageList);
}
?>
Run Code Online (Sandbox Code Playgroud)
但是我得到警告
Notice (8): Undefined variable: messageLists [APP\views\pages\home.ctp, line 9]
Run Code Online (Sandbox Code Playgroud)
我app/config/routes.php有:
/**
* Here, we are connecting '/' (base path) to controller called 'Pages',
* its action called 'display', and we pass a param to select the view file
* to use (in this case, /app/views/pages/home.ctp)...
*/
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); …Run Code Online (Sandbox Code Playgroud) 这取决于.
a)当然,但是因为整个项目变成了一个.dll,从性能的角度来看,如果你有7个控制器,每行300行代码,而一个控制器有2100行,这真的很重要吗?(如果没有关注点分离,显然可读性和紧耦合是问题)
b)只要考虑到关注点的分离,一个控制器中的代码行数是不是问题?
c)一个控制器中有多少行代码可能是需要重构的标志?(500,1000,5000,10000)?
在我的表中,我有一个列,每行都有一个复选框.我希望能够删除所有选定的项目.我找到了这个网站的代码,并根据我自己的东西进行了修改. 链接
我按照网站的复选框命名约定,如下:
<td> <?php echo $this->Form->checkbox('LocalClocks.id.['.$LocalClock['LocalClock']['id'].']', array('value' => $LocalClock['LocalClock']['id'])); ?></td>
Run Code Online (Sandbox Code Playgroud)
这是我的控制器中deleteSelected()函数的代码:
public function deleteSelected()
{
foreach($this->data['LocalClocks'] as $key => $value)
{
if($value != 0)
{
$this->LocalClock->del($value);
}
}
$this->redirect($this->referer());
}
Run Code Online (Sandbox Code Playgroud)
这是实际删除按钮的代码(以防万一需要):
<?php echo $this->Form->postLink('Delete Selected', array('action' => 'deleteSelected'), array('confirm' => 'Are you sure?')); ?>
Run Code Online (Sandbox Code Playgroud)
我认为有几件事可能是问题所在:
任何帮助都会很棒.
我目前正在学习框架"CodeIgniter".但我的表单验证有问题.首先,让我告诉你我的观点:
<form method="post" action="connexion">
<label for="pseudo">Pseudo : </label>
<input type="text" name="pseudo" value="" />
<label for="mdp">Mot de passe :</label>
<input type="password" name="mdp" value="" />
<input type="submit" value="Envoyer" /></form>
Run Code Online (Sandbox Code Playgroud)
我的控制器:
public function connexion()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('pseudo', '"user name"', 'trim|required|min_length[5]|max_length[52]|alpha_dash|encode_php_tags|xss_clean');
$this->form_validation->set_rules('mdp', '"password"', 'trim|required|min_length[5]|max_length[52]|alpha_dash|encode_php_tags|xss_clean');
if($this->form_validation->run())
{
$this->load->view('connexion_ok');
}
else
{
$this->load->view('form');
}
}
Run Code Online (Sandbox Code Playgroud)
当我在set_rules()中删除控制器中的"xss_clean"过滤器时,它运行正常,表单有效.如果存在"xss_clean",则它不起作用,它在其他地方.我在输入中不使用特殊字符,只使用字母.
在设置中我把它设为true:$ config ['global_xss_filtering'] = TRUE;
我读到某处"xss_clean"过滤器没用.我还能用什么?也许帮助者或其他什么?谢谢
I have some app with JWT authentication. And currently, I have such controller:
@RestController
@RequestMapping("users")
public class UserController {
@PostMapping(value = "{userId}/rate/inc")
public Double incRate(@PathVariable Long userId) {
return service.incUserRate(userId);
}
}
Run Code Online (Sandbox Code Playgroud)
But, I want to get user by the token in the filter and pass it as a method's param. For example:
@PostMapping(value = "/rate/inc")
public Double incRate(User user) {
returnservice.incUserRate(user);
}
Run Code Online (Sandbox Code Playgroud)
Is this possible?
controller ×10
cakephp ×3
php ×3
codeigniter ×2
model ×2
view ×2
cakephp-1.2 ×1
checkbox ×1
init ×1
iphone ×1
jwt ×1
laravel ×1
objective-c ×1
routes ×1
spring ×1
spring-boot ×1