hmvc modules form_validation session
abin2011 opened this issue · 22 comments
Codeigniter version: 2.2.0
HMVC:codeigniter-hmvc-modules
The problem:
the form_validation set_value() function is not work!
My code :
call jens
Why are you using a $this->load->controller? It's really neccesary? You are breaking the CMV paradigm there. Depending of which version of CI you have (can't remember right now if 2.2 was one of them), the problem should be there, because you are loading two different controllers, and also loading all the autoload libraries two times, so the set_value and a lot more methods won't work as you expect.
If you want to use this->controller as a loader for zones of your views, you should try the template library that jens has that uses views instead of controllers. Or use the views yourself. Try that (not using the controller loading) and let us know!
This problem as it appears on the controller
Don't understand what you are trying to say there, mate XD
Now comment the $this->load->controller line, don't use it, don't use the header, just for trial, and launch the form and tell if withouth the $this->load->controller it works fine.
if don't use it
the set_value('name') is work!
but I need to write like this.
Because header footer are common!
like this
https://github.com/Bigwebmaster/codeigniter-modular-extensions-hmvc
When using form validation with MX you will need to extend the CI_Form_validation class as shown below,
:::php
load->library('form_validation'); $this->form_validation->CI =& $this; } ``` }Ok, the problem, as I have said, it's that, when you use $this->load->controller, you initialize again all the libraries that are in the autoload. SO, you lose all previous data in EVERY library, helper, model, etc...
I suggest that you use a template system, if you are using common views in the generation of the web, like the one that jenssegers has in https://github.com/jenssegers/codeigniter-template-library (I have used it and I liked a lot, really!). OR you can change the $this->load->controler to a $this->load->(anything) (I suggest a view).
I don't know what you do in the header controller, but you should never use controller loading (being able to do something doesn't mean that it's a good idea doing that).
If I were doing a project, I'll use the template system OR a view to load the header and footers. Don't know if that's possible in yours.
About the other hvmc library, I personally have used it in the past, but didn't like it much. I think that the jes module it's more elegant, faster and gives less problems.
About the use of $this in the form_validation in this module, I haven't used it because it's not neccesary, I don't really know if that would solve your problem, but it doesn't seem plausible.
Whatever you do, if it finally works, please tell and close the issue if you can. If not, I'll try to help you
Sorry,
我在想怎么样告诉你我的想法和理解.
我用中文可以吗?
As long as google translate can do it's work, yes XD
这个 Codeigniter HMVC 扩展
难道不能在一个Controller里面调用另外一个Controller吗?
我看那实例代码上是可以在Controller中实现$this->load->controller('blogs/random', array('specials'));调用的.
那既然可以,本身应该不能影响form_validation的工作啊.
我明白你说的$this->load->controller 等于重新初始化了所有library, helper, model, etc...
但是 我现在想的是 能不能预留一个扩展或者变量 让我能继承之前的 form_validation
谢谢你回复我,Patroklo ,thank you!
你是怎么样实现验证的呢?
如果你用HMVC,前提是,你也在Controller中调用了其他Controller.
As I have said, being able to do something doesn't mean that you should do it. In this case you have to change the $this->load->controller into something else and everything will work again. I'm trying to think of a way of using the loading controller method whitout that problem and whitout extending the controller class, but I can't think of one right now.
我采用HVMC主要的原因是我想分开每一个模块,同时在我需要的时候我能组装起来
比如我现在的:样式mvc,菜单mvc,导航mvc,状态栏mvc 他们组装起来就是一个共同的 header
同时我可以在后台控制 样式,菜单,导航.
现在 form_validation 的 set_value('name') 这样不能工作
但是我仍然可以在 Controller中写
$data['name']=$this->input->post('name')
然后在Views中写
input type="text" name="name" value=""
加个默认值来实现,set_value('Field',$default) 通过$default来实现
但是这样无形中我要写多很多$data['name']=$this->input->post('name')...
所以我就希望能不能 预留一个扩展,然后让form_validation 自行扩展.
You can extend the class controller in order to only load libraries once. Then you will be able to use this->load->controller without a problem.
Something like the __construct method of this class https://github.com/Patroklo/codeigniter-mashup-cooperative/blob/master/application/core/AJAX_Controller.php
OK,I try it,
thank you! you are vary nice!
If you have any problem just aks here.
Hi, Patroklo
set_value() 方法不能获取值的问题 我通过在Controller $this->data['name']=$this->input->post('name');处理了
但是 发现 session的闪出数据 进行提示的时候 又不行了
$this->session->set_flashdata('item', 'value');
this $this->session->flashdata('item'); is not working
HMVC 真是丢失了很多librarie