Closed VeZoul closed 11 years ago
How you access $aDatas in view?
This is the content of the view :
<?php echo $iNumberMessages; ?>
it should be
echo set_value('iNumberMessages', isset($aDatas) ? $aDatas['iNumberMessages'] : ''
No, set_value helps with forms / preserving user input on validation failure. I don't think there's any reason to use it here.
then, just use
$aDatas['iNumberMessages']
Nope, that's definitely not it either.
Does not work either indeed
I'm not sure what the problem is yet. However I think it would be better design to put the method in a model (or possibly a library), and have it return a PHP integer.
You can then load the model/library from any controller.
interesting, I can use this in my view as well, it's working properly! I have same type data array which I can access array value by name.
Also HMVC (i.e. Modules) is kinda un-loved. I don't think it's caused us much trouble in Bonfire, but if there's no specific reason to tie yourself to it, then I'd avoid Modules::run() :).
Sample :
#controller
$this->load->model('customer/customer_model');
$this->db->select('core_customers.*, storename')->from('core_customers')->join('core_stores', 'core_customers.homestore = core_stores.storeid')->where('userid', $this->current_user->id);
$query = $this->db->get();
$customer = array(
'metrono' => $query->row()->metrono,
'shortname' => $query->row()->shortname,
'homestore' => $query->row()->storename,
'taxoffice' => $query->row()->taxoffice
);
Template::set('customer', $customer);
#view
<input class="span4 uneditable-input" type="text" id="homestore" name="homestore" value="<?php echo set_value('homestore', isset($customer) ? $customer['homestore'] : '') ?>"/>
Ok, it seems that the problem is caused by the parameter passed to the function get_number_new_messages This means that :
<?php echo Modules::run('messages/messages/get_number_new_messages'); ?>
works where that :
<?php echo Modules::run('messages/messages/get_number_new_messages/15'); ?>
doesn't
I'll see if I really need to use modules::run as you said and if it's the case, I'll create differents functions
@artlantis Your code is different. Please compare your posted code with @VeZoul's posted code.
I know debugging is a difficult skill. Perhaps you could make it clearer when your comments are suggestions, and you're not 100% sure about what's going on. Thanks.
I don't related with your problem but in HMVC site, there is quote like below :
Notes:
_To use HMVC functionality, such as Modules::run(), controllers must extend the MXController class.
To use Modular Separation only, without HMVC, controllers will extend the CodeIgniter Controller class.
You must use PHP5 style constructors in your controllers*
@VeZoul haha, I can imagine that.
If you look at the docs at https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc, the examples show params being passed separately. I.e. Modules::run('messages/messages/get_number_new_messages', 15)
- maybe that would work.
Ahhh you saved my day ! I missed that line it seems... Indeed it looks like it works ! Thanks !!! :+1:
@artlantis Good thought, but it should be covered in most cases. Bonfire's Controller classes already extend MX_Controller. So as long as you extend our Front_Controller / Admin_Controller etc., it should cover that requirement.
@sourcejedi @VeZoul good cooperation, I am glad to solve your problem. Happy coding :)
I have a controller that lists some offers I created. Foreach offer, I want to display the number of unread messages associated.
I thought using modules::run but when I call :
Nothing is displayed. If I call the get_number_new_messages directly in my url, it returns me the int I want (ie: "1")
Here is my messages controller function :
I also call
and
in one of my theme file
Am I missing something... ?