Welcome Guest, Not a member yet? Register   Sign In
Template Library and HMVC
#1

[eluser]umefarooq[/eluser]
Hi Happy new year

i was trying to use Template Library with HMVC, i followed the Template library's user guide to setup library and i put template.php file in my module view folder but no luck it gives me the following error

Quote:An Error Was Encountered

Either you have not provided a master template or the one provided does not exist in C:\AppServ\www\code/system/application/views. Remember to include the extension if other than ".php"

but after putting template.php file in CI application/view folder along with my module's view folder its working fine and its taking template.php file from my moduler view folder im not understanding the working of template library its should follow the path's given to it. i want to ask is it right way and will not create any problem to application after deployment i need CI community's suggestions
#2

[eluser]Colin Williams[/eluser]
I'd love to help, but I have no knowledge of the HMVC library. I know people have made the two libraries compatible, so hopefully one of them will help you out.

Template works with CI's conventions, which say that views are stored in the application/views folder. The ME - HMVC system subverts this convention and allows you to put your view files elsewhere. This is why there is a breakdown. If you possible can, keep your master template in the application/views folder.
#3

[eluser]Flak[/eluser]
If someone has made two libraries work together please post a tip here. Its so crucial. I think more support needed because both libs are great and should work together.


@colin, I think is your part to play Smile

Jerome has made his template work. He uses this method of telling which controller:

Code:
function load_partial($template = '', $view = '' , $view_data = array(), $return = FALSE)
{
    $this->set('contents', $this->template_data['controller']->load->view($view, $view_data, TRUE));
    return $this->template_data['controller']->load->view($template, $this->template_data, $return);
}

I think tuning a bit your Template.php file on lib to load view depends on controller would be cool.

Here is my idea.

Keep Master template on View, then load regions view from module/view

in:
-module - page - controller - page.php

I define what view to load for what purpose.


-module - page - view
- view - content.php
- view - comment.php
'
'
'
And in view I have let say generic template.
view - template.php
- header.php
- footer.php

Conclusion : This will make my modules interdependent from templates, so if I want to make new module I don't have to touch templates, only add my regions on my module view.

Hope it makes sense.
#4

[eluser]Colin Williams[/eluser]
I think the only problem is when Template checks for the existence of the view files before using them. I don't think it would be too much of a problem to throw in a quick check for module-based views. I might put it together tonight. Haven't played around with the code in awhile.

UPDATE:

Any ME - HMVC users wanna glance over this and see if it looks good on the surface?

Code:
$mod_dir = 'modules/'. $this->CI->uri->rsegment(1) .'/';
       return (
           (file_exists(APPPATH .'views/'. $view . EXT) or file_exists(APPPATH .'views/'. $view))
           or
           (file_exists(APPPATH . $mod_dir .'views/'. $view . EXT) or file_exists(APPPATH . $mod_dir .'views/'. $view))
         );
#5

[eluser]tyuwan[/eluser]
where do i put that code? anyone found a solution yet?
#6

[eluser]Colin Williams[/eluser]
The current working version of Template is all over the place, so there are many updates that are yet untested. I might do some sort of beta release soon, Template 1.5b.

In the meantime, try this patch:

Step 1, add this method to the Template class:

Code:
/**
     * Check for the existance of a view
     *
     * @access    private
     * @param    string    path to view file
     * @return    bool    TRUE if file found, else FALSE
     */
  
   function _view_exists($view)
   {
       $mod_dir = 'modules/'. $this->CI->uri->rsegment(1) .'/';
       return (
           (file_exists(APPPATH .'views/'. $view . EXT) or file_exists(APPPATH .'views/'. $view))
           or
           (file_exists(APPPATH . $mod_dir .'views/'. $view . EXT) or file_exists(APPPATH . $mod_dir .'views/'. $view))
         );
   }

Step 2, replace lines 364-369 AND lines 406-411 with this code:

Code:
if ($this->_view_exists($suggestion))
{
   // Just change the $view arg so the rest of our method works as normal
   $view = $suggestion;
   break;
}

Lastly, change line 108 to

Code:
if ($this->_view_exists($filename))

Essentially, you are replacing all file_exists() checks with the "ME-HMVC aware" _view_exists() method. I must stress that this is highly untested and my knowledge of the Modular Extensions, er, extension is limited.

If you just want the latest-and-greatest version of the whole class, PM me.
#7

[eluser]mr_menace[/eluser]
@Flak, I hope the following will help. I was able to set up template in the views/ folder and all the modules may work with it.template->write_view() works fine too, and is able to find the correct view in <APPPATH>modules/mymodule/views.If I understood correctly, your layout would work with the solution below.

After I made the changes suggested by Collin above, I was getting an error saying "Unable to load the requested file: <APPPATH>/modules/mymodule/views/template.php". It was searching in the module directory only, but template.php file was sitting in the <APPPATH>/views folder, since I want to reference a single master template it from any module.

After pouring through the Template/HMVC code, I realized that these two are using different Loader classes, and here's how I got them working in harmony.

First, I added the following method to Template.php
Code:
/**
* Override default CI loader object with another
* @return none
* @param object CI object to be set as loader
*/
function setLoader(&$l){
    $this->CI->load = &$l;
}

After that, I just added the following lines the constructor of my controller class
Code:
$this->load->library('template');
$this->template->setLoader($this->load); //add this line. overrides Template 'load' object
If you are autoloading the template library, then the 1st line does not have to be inside the constructor, otherwise you have to make sure the 2 lines appear in the order shown above.

I am not sure of the repercussions of replacing the Template 'load' object with the HMVC one, perhaps someone more familiar with Template can enlighten me if this is safe to do. I have not tested this for long, but it has been working fine (so far).
#8

[eluser]Colin Williams[/eluser]
Thanks for investigating further, mr_menace.
#9

[eluser]mr_menace[/eluser]
Don't mention it. I actually joined this forum specifically for this thread - I was hoping that someone would have found a solution. Since I needed the solution badly, I figured I might as well give it a try. A side-effect of this is that I now know a bit more of CI, Template and HMVC than I knew before. Additional bonus - am now a member of this forum. I hope someone out there still finds this useful.

As a sidenote, I find it a bit weird that I spent more than 4 hours to come up with a solution that's basically 2 lines of code. The bulk of that time was spent trying to figure out the architecture and what on earth was going on behind the scenes. All in all worth it
#10

[eluser]Colin Williams[/eluser]
That information is very valuable. As you can probably tell, I keep taking on this issue of compatibility with ME - HMVC half-heartedly since I'm not a user of HMVC myself. Ultimately I'd prefer to alter the class so it just works, not by introducing a new method.




Theme © iAndrew 2016 - Forum software by © MyBB